2024-07-04 17:21:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\UserInvite;
|
|
|
|
|
use Carbon\Carbon;
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
use App\Rules\ValidHCaptcha;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-07-04 17:21:36 +02:00
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = $this->actingAsProUser();
|
|
|
|
|
$this->workspace = $this->createUserWorkspace($this->user);
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
Http::fake([
|
|
|
|
|
ValidHCaptcha::H_CAPTCHA_VERIFY_URL => Http::response(['success' => true])
|
|
|
|
|
]);
|
2024-09-24 12:16:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2024-07-04 17:21:36 +02:00
|
|
|
it('can register with invite token', function () {
|
|
|
|
|
$email = 'invitee@gmail.com';
|
|
|
|
|
$inviteData = ['email' => $email, 'role' => 'user'];
|
2024-09-24 12:16:20 +02:00
|
|
|
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
|
2024-07-04 17:21:36 +02:00
|
|
|
->assertSuccessful();
|
|
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->invites()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
$userInvite = UserInvite::latest()->first();
|
|
|
|
|
$token = $userInvite->token;
|
|
|
|
|
|
|
|
|
|
$this->postJson('/logout')
|
|
|
|
|
->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
// Register with token
|
|
|
|
|
$response = $this->postJson('/register', [
|
|
|
|
|
'name' => 'Invitee',
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
|
'password' => 'secret',
|
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
|
'agree_terms' => true,
|
|
|
|
|
'invite_token' => $token,
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
'h-captcha-response' => 'test-token',
|
2024-07-04 17:21:36 +02:00
|
|
|
]);
|
|
|
|
|
$response->assertSuccessful();
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->users()->count())->toBe(2);
|
2024-07-04 17:21:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot register with expired invite token', function () {
|
|
|
|
|
$email = 'invitee@gmail.com';
|
|
|
|
|
$inviteData = ['email' => $email, 'role' => 'user'];
|
2024-09-24 12:16:20 +02:00
|
|
|
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
|
2024-07-04 17:21:36 +02:00
|
|
|
->assertSuccessful();
|
|
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->invites()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
$userInvite = UserInvite::latest()->first();
|
|
|
|
|
$token = $userInvite->token;
|
|
|
|
|
|
|
|
|
|
$this->postJson('/logout')
|
|
|
|
|
->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
Carbon::setTestNow(now()->addDays(8));
|
|
|
|
|
// Register with token
|
|
|
|
|
$response = $this->postJson('/register', [
|
|
|
|
|
'name' => 'Invitee',
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
|
'password' => 'secret',
|
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
|
'agree_terms' => true,
|
|
|
|
|
'invite_token' => $token,
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
'h-captcha-response' => 'test-token',
|
2024-07-04 17:21:36 +02:00
|
|
|
]);
|
|
|
|
|
$response->assertStatus(400)->assertJson([
|
|
|
|
|
'message' => 'Invite token has expired.',
|
|
|
|
|
]);
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->users()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot re-register with accepted invite token', function () {
|
|
|
|
|
$email = 'invitee@gmail.com';
|
|
|
|
|
$inviteData = ['email' => $email, 'role' => 'user'];
|
2024-09-24 12:16:20 +02:00
|
|
|
$this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
|
2024-07-04 17:21:36 +02:00
|
|
|
->assertSuccessful();
|
|
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->invites()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
$userInvite = UserInvite::latest()->first();
|
|
|
|
|
$token = $userInvite->token;
|
|
|
|
|
|
|
|
|
|
$this->postJson('/logout')
|
|
|
|
|
->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
// Register with token
|
|
|
|
|
$response = $this->postJson('/register', [
|
|
|
|
|
'name' => 'Invitee',
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
|
'password' => 'secret',
|
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
|
'agree_terms' => true,
|
|
|
|
|
'invite_token' => $token,
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
'h-captcha-response' => 'test-token',
|
2024-07-04 17:21:36 +02:00
|
|
|
]);
|
|
|
|
|
$response->assertSuccessful();
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->users()->count())->toBe(2);
|
2024-07-04 17:21:36 +02:00
|
|
|
|
|
|
|
|
$this->postJson('/logout')
|
2024-09-24 12:16:20 +02:00
|
|
|
->assertSuccessful();
|
2024-07-04 17:21:36 +02:00
|
|
|
|
|
|
|
|
// Register again with same used token
|
|
|
|
|
$response = $this->postJson('/register', [
|
|
|
|
|
'name' => 'Invitee',
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
|
'password' => 'secret',
|
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
|
'agree_terms' => true,
|
|
|
|
|
'invite_token' => $token,
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
'h-captcha-response' => 'test-token',
|
2024-07-04 17:21:36 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(422)->assertJson([
|
|
|
|
|
'message' => 'The email has already been taken.',
|
|
|
|
|
]);
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->users()->count())->toBe(2);
|
2024-07-04 17:21:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can cancel user invite', function () {
|
|
|
|
|
$email = 'invitee@gmail.com';
|
|
|
|
|
$inviteData = ['email' => $email, 'role' => 'user'];
|
2024-09-24 12:16:20 +02:00
|
|
|
$response = $this->postJson(route('open.workspaces.users.add', $this->workspace->id), $inviteData)
|
2024-07-04 17:21:36 +02:00
|
|
|
->assertSuccessful();
|
|
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->invites()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
$userInvite = UserInvite::latest()->first();
|
|
|
|
|
$token = $userInvite->token;
|
|
|
|
|
|
|
|
|
|
// Cancel the invite
|
2024-09-24 12:16:20 +02:00
|
|
|
$this->deleteJson(route('open.workspaces.invites.cancel', ['workspaceId' => $this->workspace->id, 'inviteId' => $userInvite->id]))
|
2024-07-04 17:21:36 +02:00
|
|
|
->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
$this->postJson('/logout')
|
|
|
|
|
->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
// Register with token
|
|
|
|
|
$response = $this->postJson('/register', [
|
|
|
|
|
'name' => 'Invitee',
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
|
'password' => 'secret',
|
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
|
'agree_terms' => true,
|
|
|
|
|
'invite_token' => $token,
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
'h-captcha-response' => 'test-token',
|
2024-07-04 17:21:36 +02:00
|
|
|
]);
|
|
|
|
|
$response->assertStatus(400)->assertJson([
|
|
|
|
|
'message' => 'Invite token is invalid.',
|
|
|
|
|
]);
|
|
|
|
|
|
2024-09-24 12:16:20 +02:00
|
|
|
expect($this->workspace->users()->count())->toBe(1);
|
2024-07-04 17:21:36 +02:00
|
|
|
});
|