Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chainguard-dev/go-oidctest
Library for creating fake OIDC providers in tests
https://github.com/chainguard-dev/go-oidctest
go golang golang-testing
Last synced: about 1 month ago
JSON representation
Library for creating fake OIDC providers in tests
- Host: GitHub
- URL: https://github.com/chainguard-dev/go-oidctest
- Owner: chainguard-dev
- License: apache-2.0
- Created: 2022-03-21T16:52:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T16:37:13.000Z (8 months ago)
- Last Synced: 2024-05-06T17:58:26.498Z (8 months ago)
- Topics: go, golang, golang-testing
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-oidc-test
Library for creating fake OIDC issuers in tests.## Test issuer
`oidctest.NewIssuer` creates a fake OIDC issuer. It returns its signing key as
well as its issuer URL.Example:
```go
ctx := context.Background()signer, iss := oidctest.NewIssuer(t)
token, err := jwt.Signed(signer).Claims(jwt.Claims{
Issuer: iss,
IssuedAt: jwt.NewNumericDate(time.Now()),
Expiry: jwt.NewNumericDate(time.Now().Add(30 * time.Minute)),
Subject: "test-subject",
Audience: jwt.Audience{"test-audience"},
}).CompactSerialize()
if err != nil {
t.Fatalf("CompactSerialize() = %v", err)
}// Verify the token is valid.
provider, err := oidc.NewProvider(ctx, iss)
if err != nil {
t.Errorf("constructing %q provider: %v", iss, err)
}verifier := provider.Verifier(&oidc.Config{SkipClientIDCheck: true})
if _, err := verifier.Verify(ctx, token); err != nil {
t.Errorf("verifying token: %v", err)
}
```