Export the reviewed application-neutral package set through the exact public allowlist. Development history and private application evidence remain outside this canonical source root. Developed with material AI assistance under maintainer review. Signed-off-by: Cole Speelman <crspeelman@gmail.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSessionDistinguishesMissingFromUnavailableStorage(t *testing.T) {
|
||||
service, err := New(repositoryStub{sessionErr: ErrSessionNotFound}, Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = service.Session(t.Context(), strings.Repeat("x", 43)); !errors.Is(err, ErrSessionNotFound) {
|
||||
t.Fatalf("missing err=%v", err)
|
||||
}
|
||||
|
||||
storageErr := errors.New("storage offline")
|
||||
service, err = New(repositoryStub{sessionErr: storageErr}, Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = service.Session(t.Context(), strings.Repeat("x", 43)); !errors.Is(err, storageErr) || errors.Is(err, ErrSessionNotFound) {
|
||||
t.Fatalf("storage err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type repositoryStub struct{ sessionErr error }
|
||||
|
||||
func (repositoryStub) CreateUser(context.Context, User, string) error { return nil }
|
||||
func (repositoryStub) CredentialByIdentifier(context.Context, string) (User, string, error) {
|
||||
return User{}, "", ErrUserNotFound
|
||||
}
|
||||
func (repositoryStub) UpdateLastLogin(context.Context, string, time.Time) error { return nil }
|
||||
func (repositoryStub) CreateSession(context.Context, Session) error { return nil }
|
||||
func (repository repositoryStub) PrincipalBySession(context.Context, [32]byte, time.Time) (Principal, Session, error) {
|
||||
return Principal{}, Session{}, repository.sessionErr
|
||||
}
|
||||
func (repositoryStub) TouchSession(context.Context, [32]byte, time.Time) error { return nil }
|
||||
func (repositoryStub) DeleteSession(context.Context, [32]byte) error { return nil }
|
||||
func (repositoryStub) RevokeUserSessions(context.Context, string) error { return nil }
|
||||
func (repositoryStub) SeedPolicy(context.Context, PolicySeed) error { return nil }
|
||||
func (repositoryStub) GrantRole(context.Context, string, string, time.Time) error {
|
||||
return nil
|
||||
}
|
||||
func (repositoryStub) AppendAudit(context.Context, AuditEvent) error { return nil }
|
||||
Reference in New Issue
Block a user