Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
1 change: 0 additions & 1 deletion js/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function useChallenge(props: ChallengeProps, factors: Record<string, Fact
form,
props,
Component: factors[props.factor] as FactorComponent | undefined,
alternatives: props.alternatives,
submit,
verifyKey,
switchTo: (option: AuthenticatorSummary) => switchTo(props, option),
Expand Down
1 change: 0 additions & 1 deletion js/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function useChallenge(props: ChallengeProps, factors: Record<string, Comp
form,
props,
component: computed(() => factors[props.factor] as Component | undefined),
alternatives: computed(() => props.alternatives),
submit,
verifyKey,
switchTo: (option: AuthenticatorSummary) => switchTo(props, option),
Expand Down
1 change: 0 additions & 1 deletion js/tests/vue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('')

Expand Down
4 changes: 3 additions & 1 deletion src/Events/FactorVerified.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Events/LoggedOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/KeyringManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string<Factor>|Factor|Closure(Container): Factor> $factors
*/
Expand Down
11 changes: 1 addition & 10 deletions tests/Feature/ExtendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 3 additions & 7 deletions tests/Feature/FeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
12 changes: 7 additions & 5 deletions tests/Feature/PublicApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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(), '/')])
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
14 changes: 0 additions & 14 deletions tests/Feature/StrictTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()), "<?php\n\ndeclare(strict_types=1);\n"))
->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);
Expand Down
141 changes: 141 additions & 0 deletions tests/Fixtures/public-api.json
Original file line number Diff line number Diff line change
@@ -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}",
Expand Down
Loading