diff --git a/UPGRADE.md b/UPGRADE.md index 0cca5824..123f0e5c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,4 +2,4 @@ Keyring has no tagged release yet, so there's nothing to upgrade from. This guide starts with the first release, and will list anything you need to change when updating from one release to the next. -What counts as a change you'd need to act on is in the README's [What's Stable](README.md#whats-stable). A test (`tests/Feature/PublicApiTest.php`) fails when a route, middleware alias, facade method, contract, event or email type is renamed or removed, so one can't change without an entry here. +What counts as a change you'd need to act on is in the README's [What's Stable](README.md#whats-stable). A test (`tests/Feature/PublicApiTest.php`) fails when a config default changes, or a route, middleware alias, facade method, contract, event or email type is renamed or removed, so one can't change without an entry here. diff --git a/docs/frontend.md b/docs/frontend.md index b284af29..0cb603b1 100644 --- a/docs/frontend.md +++ b/docs/frontend.md @@ -137,7 +137,6 @@ const challenge = useChallenge(props, factors) | `switchTo(option)` | Visits the challenge page for one of `props.alternatives`. | | `send()` | Asks the server to send a code, for factors that send one. | | `verifyKey()` | Runs the WebAuthn ceremony with `props.challenge.options` and submits the result. Calling it again while the prompt is open replaces that prompt. Closing the prompt does nothing; other browser errors are set on `form.errors.credential`. | -| `alternatives` | `props.alternatives`. | Factor components receive `challenge`, and read the page from `challenge.props`. diff --git a/js/src/react.ts b/js/src/react.ts index 1219f896..7fc18086 100644 --- a/js/src/react.ts +++ b/js/src/react.ts @@ -47,7 +47,6 @@ export function useChallenge(props: ChallengeProps, factors: Record switchTo(props, option), diff --git a/js/src/vue.ts b/js/src/vue.ts index e3e1e142..5f5a08fd 100644 --- a/js/src/vue.ts +++ b/js/src/vue.ts @@ -47,7 +47,6 @@ export function useChallenge(props: ChallengeProps, factors: Record factors[props.factor] as Component | undefined), - alternatives: computed(() => props.alternatives), submit, verifyKey, switchTo: (option: AuthenticatorSummary) => switchTo(props, option), diff --git a/js/tests/vue.test.ts b/js/tests/vue.test.ts index 89161e46..b36ec361 100644 --- a/js/tests/vue.test.ts +++ b/js/tests/vue.test.ts @@ -22,7 +22,6 @@ describe('vue useChallenge', () => { const challenge = useChallenge(props, { totp: Code, recovery: Recovery }) expect(challenge.component).toBe(Code) - expect(challenge.alternatives).toHaveLength(1) expect(challenge.props.authenticator.name).toBe('Phone') expect(challenge.form.code).toBe('') diff --git a/src/Events/FactorVerified.php b/src/Events/FactorVerified.php index cbb9b80c..9e491792 100644 --- a/src/Events/FactorVerified.php +++ b/src/Events/FactorVerified.php @@ -11,7 +11,9 @@ use Keyring\Models\Authenticator; /** - * A factor was verified successfully. + * A factor's proof was right, at sign in or step-up. When the policy asks + * for more than one, each fires this: Authenticated or Confirmed says the + * whole attempt is done. */ class FactorVerified { diff --git a/src/Events/LoggedOut.php b/src/Events/LoggedOut.php index eb698ba7..a0d38e8d 100644 --- a/src/Events/LoggedOut.php +++ b/src/Events/LoggedOut.php @@ -9,7 +9,8 @@ use Illuminate\Queue\SerializesModels; /** - * The user signed out. + * The user signed out on purpose. A session Keyring ends on its own is + * SessionEnded. */ class LoggedOut { diff --git a/src/KeyringManager.php b/src/KeyringManager.php index 02fdf528..ec546907 100644 --- a/src/KeyringManager.php +++ b/src/KeyringManager.php @@ -93,7 +93,8 @@ public function __construct( } /** - * Set the factors users may sign in with. + * The factors users may sign in with. This replaces the list, so name + * the password too if it stays. * * @param list|Factor|Closure(Container): Factor> $factors */ diff --git a/tests/Feature/ExtendingTest.php b/tests/Feature/ExtendingTest.php index 2854c543..18484c6e 100644 --- a/tests/Feature/ExtendingTest.php +++ b/tests/Feature/ExtendingTest.php @@ -17,7 +17,6 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Validator; -use Illuminate\Support\Str; use Illuminate\Validation\Rules\Password; use Illuminate\Validation\ValidationException; use Keyring\Changes\EmailChanges; @@ -145,15 +144,7 @@ public function toResponse($request) it('sends its own notification for every type but a suspected clone, until the app says otherwise', function () { $keyring = new KeyringManager(new FactorRegistry, app(ProtectedAttributes::class)); - foreach (array_diff(KeyringManager::NOTIFICATIONS, ['clone_suspected']) as $type) { - expect($keyring->notification($type, [ - 'when' => 'Monday', 'code' => '12345678', 'minutes' => 10, 'email' => 'n•••@example.com', - 'url' => 'https://example.com/link', 'expiresAt' => now()->addDay(), 'revertUrl' => 'https://example.com/revert', - 'loginUrl' => 'https://example.com/login', - ]))->toBeInstanceOf('Keyring\\Notifications\\'.Str::studly($type)); - } - - expect($keyring->hasNotification('clone_suspected'))->toBeFalse() + expect(collect(KeyringManager::NOTIFICATIONS)->reject(fn (string $type) => $keyring->hasNotification($type))->values()->all())->toBe(['clone_suspected']) ->and($keyring->notification('clone_suspected', ['when' => 'Monday']))->toBeNull(); // The app's own class for one, another turned off, and the clone turned on. diff --git a/tests/Feature/FeaturesTest.php b/tests/Feature/FeaturesTest.php index e5a9a066..29e7b425 100644 --- a/tests/Feature/FeaturesTest.php +++ b/tests/Feature/FeaturesTest.php @@ -83,12 +83,8 @@ $this->inertia()->get(route('keyring.login.challenge'))->assertJsonPath('props.canTrustDevice', false); }); -it('starts with the password, registration, password resets, email verification, password changes, the security log and its own emails', function () { - $config = require __DIR__.'/../../config/keyring.php'; - +// What config/keyring.php starts with is in tests/Fixtures/public-api.json. +it('starts with the password alone and its own emails', function () { expect(new FactorRegistry()->all()->keys()->all())->toBe(['password']) - ->and($config['features'])->toBe([Features::registration(), Features::resetPasswords(), Features::emailVerification(), Features::updatePasswords(), Features::securityLog()]) - ->and($config['registration']['reveal_taken'])->toBeFalse() - ->and(new KeyringManager(new FactorRegistry, app(ProtectedAttributes::class))->hasNotification('password_changed'))->toBeTrue() - ->and($config['protected'])->toBe([]); + ->and(new KeyringManager(new FactorRegistry, app(ProtectedAttributes::class))->hasNotification('password_changed'))->toBeTrue(); }); diff --git a/tests/Feature/PublicApiTest.php b/tests/Feature/PublicApiTest.php index a37a1805..1203ca95 100644 --- a/tests/Feature/PublicApiTest.php +++ b/tests/Feature/PublicApiTest.php @@ -8,16 +8,17 @@ use Keyring\KeyringManager; use Keyring\UserKeyring; -// What apps build on, as the README's "What's Stable" lists it: the route -// names, the middleware aliases, the methods of the Keyring facade and of +// What apps build on, as the README's "What's Stable" lists it: the config +// options and what each is until an app sets it, the route names, the +// middleware aliases, the methods of the Keyring facade and of // Keyring::for($user), the contracts, the events and the email types. A -// rename here breaks every app that uses it, and nothing else would notice -// when the tests are renamed with it. +// rename or a new default here changes every app that uses it, and nothing +// else would notice when the tests are changed with it. // // A change that's meant: run UPDATE_PUBLIC_API=1 vendor/bin/pest // tests/Feature/PublicApiTest.php, commit tests/Fixtures/public-api.json // with it, and say so in UPGRADE.md. -it('keeps the names apps build on, or says which changed', function () { +it('keeps the names and defaults apps build on, or says which changed', function () { withFeatures(Features::all()); $methods = fn (string $class) => collect(new ReflectionClass($class)->getMethods(ReflectionMethod::IS_PUBLIC)) @@ -30,6 +31,7 @@ ->sort()->values(); $api = [ + 'defaults' => require __DIR__.'/../../config/keyring.php', 'routes' => collect(app('router')->getRoutes()->getRoutes()) ->filter(fn ($route) => $route->getName() !== null) ->mapWithKeys(fn ($route) => [$route->getName() => implode('|', array_diff($route->methods(), ['HEAD'])).' /'.ltrim($route->uri(), '/')]) diff --git a/tests/Feature/ServiceProviderTest.php b/tests/Feature/ServiceProviderTest.php index 9c2daebb..e09a570d 100644 --- a/tests/Feature/ServiceProviderTest.php +++ b/tests/Feature/ServiceProviderTest.php @@ -193,9 +193,10 @@ function withALateCacheStoreForRateLimits(): void Keyring::factors([Password::class, WebAuthn::passkeys(), WebAuthn::securityKeys()]); + expect(Keyring::registered()->keys()->all())->toBe(['password', 'passkey', 'security-key']); + // Nothing asks for the store until a challenge is answered. - expect(Keyring::registered()->keys()->all())->toBe(['password', 'passkey', 'security-key']) - ->and(app(SpentChallenges::class))->toBeInstanceOf(SpentChallenges::class); + app(SpentChallenges::class); Cache::extend('late', fn () => Cache::repository(new ArrayStore)); diff --git a/tests/Feature/StrictTypesTest.php b/tests/Feature/StrictTypesTest.php index ce3cf1a6..66288729 100644 --- a/tests/Feature/StrictTypesTest.php +++ b/tests/Feature/StrictTypesTest.php @@ -22,7 +22,6 @@ use Keyring\Support\EncryptedSession; use Keyring\Testing\VirtualAuthenticator; use ParagonIE\ConstantTime\Base64UrlSafe; -use Symfony\Component\Finder\Finder; /** * A factor that takes the code "ok", under whatever key it's given. @@ -50,19 +49,6 @@ public function verify(Attempt $attempt, Authenticator $authenticator, Request $ }; } -it('declares strict types in every php file it ships', function () { - $files = Finder::create()->files()->name('*.php')->notName('*.blade.php') - ->in(array_map(fn (string $directory) => dirname(__DIR__, 2).'/'.$directory, ['src', 'config', 'database', 'routes', 'stubs', 'lang'])); - - $missing = collect($files) - ->reject(fn (SplFileInfo $file) => str_starts_with((string) file_get_contents($file->getPathname()), "map(fn (SplFileInfo $file) => $file->getPathname()) - ->values(); - - expect($files->count())->toBeGreaterThan(200) - ->and($missing->all())->toBe([]); -}); - it('compares the signed-in user\'s id with a confirmation\'s as strings', function (Closure $stored, bool $stands) { $user = taylor(); $this->actingAs($user); diff --git a/tests/Fixtures/public-api.json b/tests/Fixtures/public-api.json index 1b4cc4d3..04e5a9b1 100644 --- a/tests/Fixtures/public-api.json +++ b/tests/Fixtures/public-api.json @@ -1,4 +1,145 @@ { + "defaults": { + "guard": "web", + "username": "email", + "email": "email", + "features": [ + "registration", + "reset-passwords", + "email-verification", + "update-passwords", + "security-log" + ], + "registration": { + "reveal_taken": false + }, + "home": "/dashboard", + "routes": true, + "prefix": "", + "domain": null, + "middleware": [ + "web", + "Keyring\\Http\\Middleware\\AddSecurityHeaders" + ], + "webauthn": { + "relying_party": { + "id": null, + "name": null + }, + "origins": [], + "timeout": "60s", + "login_options_for": "5m", + "attestation_roots": [], + "algorithms": [ + "ES256", + "EdDSA" + ], + "minimum_rsa_bits": 2048 + }, + "changes_middleware": [ + "keyring.fresh:15m" + ], + "enrollment_url": null, + "enrollment_except": [], + "password_change_url": null, + "support_contact": null, + "devices": { + "cookie": null, + "cookie_lifetime": "400d", + "limit": 50, + "trust_for": "30d", + "report_link_for": "7d", + "keep_revoked_for": "30d", + "keep_unseen_for": "365d", + "locator": "Keyring\\Devices\\NullLocator" + }, + "sessions": { + "driver": "database", + "connection": null, + "table": "keyring_sessions", + "store": null, + "max": 100, + "idle": "2h", + "remember_idle": "14d", + "absolute": "30d", + "levels": { + "aal2": { + "idle": "1h", + "absolute": "24h" + }, + "aal3": { + "idle": "15m", + "absolute": "12h" + } + }, + "end_on_lapse": false, + "middleware": true, + "remember_cookie": null, + "remember_grace": "10s" + }, + "protected": [], + "email_changes": { + "confirmable_for": "24h", + "revertable_for": "7d", + "established_after": "7d", + "sign_out_others": true, + "keep_ended_for": "30d" + }, + "passwords": { + "min_with_mfa": 8, + "min_without_mfa": 15, + "max": 128, + "uncompromised": null, + "refuse_unchecked": false, + "context": [], + "broker": null + }, + "risk": { + "levels": { + "medium": 30, + "high": 60, + "critical": 90 + }, + "recent_change": "7d", + "store": null + }, + "security_log": { + "keep_for": "180d", + "channel": null, + "context_key": "trace_id", + "refusals": 20, + "refusals_per": "1h", + "alerts": [ + "second_factor_failed", + "device_reported", + "email_change_reverted", + "clone_suspected", + "remember_me_reused" + ] + }, + "prune_at": "03:00", + "pending_logins": { + "keep_for": "10m" + }, + "enrollments": { + "keep_for": "15m" + }, + "timebox": "250ms", + "limits": { + "per_account": 5, + "per_ip": 20, + "consecutive": 100, + "consecutive_elsewhere": 80, + "remember_names_for": "30d", + "longest_lock": "24h", + "longest_ip_lock": "15m", + "lock_after": null, + "codes": 3, + "codes_per": "10m", + "notices": 5, + "notices_per": "1h" + } + }, "routes": { "keyring.authenticators.confirm": "POST /user/authenticators/{factor}/confirm", "keyring.authenticators.destroy": "DELETE /user/authenticators/{authenticator}",