mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-01 19:20:31 +00:00
pkg/security no longer contains SQL. Every provider calls a store interface
from lookup, implemented by a procedure backend (Postgres stored procedures,
the default there) and a direct backend (dialect-driven SQL for postgres,
sqlite, mysql and mssql with configurable table and column names).
- add sectypes, lookup, lookup/{dialect,procedure,direct,backends,ddl,conformance}
- split totp and providers sub packages out of the core package
- replace SQLNames/TableNames/QueryMode with lookup.Config (see breaking_changes.md)
- direct backend now covers column/row security and API-key login
- move txsettings SQL to lookup.ApplyTxSettings; remove password.go
- move schema scripts under lookup/, add reference DDL per dialect
- add a shared conformance suite; run it on sqlite, and on Postgres in a
podman/docker container (RESOLVESPEC_TEST_CONTAINERS=1)
- fix procedure schema bugs found on real Postgres: duplicate p_data
parameter, JSON null arrays, expires_at timezone casts, passkey list
GROUP BY, missing resolvespec_passkey_login; accept zone-less timestamps
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package security
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
type fakeAPIKeyAuth struct {
|
|
Authenticator
|
|
key string
|
|
}
|
|
|
|
func (f *fakeAPIKeyAuth) LoginWithAPIKey(_ context.Context, rawKey string, _ map[string]any) (*LoginResponse, error) {
|
|
if rawKey != f.key {
|
|
return nil, errInvalidAPIKey
|
|
}
|
|
return &LoginResponse{Token: "tok"}, nil
|
|
}
|
|
|
|
func TestChainLoginWithAPIKey(t *testing.T) {
|
|
ctx := context.Background()
|
|
chain := NewChainAuthenticator(&fakeAPIKeyAuth{key: "a"}, &fakeAPIKeyAuth{key: "b"})
|
|
for _, k := range []string{"a", "b"} {
|
|
if resp, err := chain.LoginWithAPIKey(ctx, k, nil); err != nil || resp.Token != "tok" {
|
|
t.Errorf("chain LoginWithAPIKey(%q) = %v, %v", k, resp, err)
|
|
}
|
|
}
|
|
if _, err := chain.LoginWithAPIKey(ctx, "bad", nil); !errors.Is(err, errInvalidAPIKey) {
|
|
t.Errorf("chain bad key error = %v, want errInvalidAPIKey", err)
|
|
}
|
|
}
|
|
|
|
func TestDatabaseAuthenticatorLoginWithAPIKey_EmptyKey(t *testing.T) {
|
|
auth := NewDatabaseAuthenticatorWithOptions(newDirectTestDB(t), DatabaseAuthenticatorOptions{})
|
|
if _, err := auth.LoginWithAPIKey(context.Background(), "", nil); !errors.Is(err, errInvalidAPIKey) {
|
|
t.Errorf("empty key error = %v, want errInvalidAPIKey", err)
|
|
}
|
|
}
|