Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

2.1 KB
Raw Blame
<?php

use App\Models\InstanceSettings;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

beforeEach(function () {
    config()->set('app.maintenance.store', 'array');

    InstanceSettings::query()->forceCreate(['id' => 0]);
});

it('rate limits repeated forgot password attempts from the same ip', function () {
    foreach (range(1, 3) as $attempt) {
        $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.20'])
            ->post('/forgot-password', [
                'email' => "user{$attempt}@example.com",
            ])
            ->assertSessionHasNoErrors();
    }

    $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.20'])
        ->post('/forgot-password', [
            'email' => '[email protected]',
        ])
        ->assertTooManyRequests();
});

it('rate limits dotted plus-address forgot password variants of the same email identity across ips', function () {
    $emails = [
        '[email protected]',
        '[email protected]',
        '[email protected]',
    ];

    foreach ($emails as $index => $email) {
        $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.'.($index + 30)])
            ->post('/forgot-password', [
                'email' => $email,
            ])
            ->assertSessionHasNoErrors();
    }

    $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.99'])
        ->post('/forgot-password', [
            'email' => '[email protected]',
        ])
        ->assertTooManyRequests();
});

it('keeps distinct dotted and plus-addressed mailboxes in separate forgot password buckets on ordinary domains', function () {
    $emails = [
        '[email protected]',
        '[email protected]',
        '[email protected]',
        '[email protected]',
    ];

    foreach ($emails as $index => $email) {
        $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.'.($index + 120)])
            ->post('/forgot-password', [
                'email' => $email,
            ])
            ->assertSessionHasNoErrors();
    }
});