Files
upstream-corteza/server/store/tests/auth_oa2tokens.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

89 lines
2.3 KiB
Go

package tests
import (
"context"
"testing"
"time"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/rand"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/types"
"github.com/stretchr/testify/require"
)
func testAuthOa2tokens(t *testing.T, s store.AuthOa2tokens) {
var (
ctx = context.Background()
req = require.New(t)
makeNew = func() *types.AuthOa2token {
// minimum data set for new authOa2token
return &types.AuthOa2token{
ID: id.Next(),
CreatedAt: time.Now(),
ExpiresAt: time.Now(),
Access: string(rand.Bytes(5)),
Code: string(rand.Bytes(5)),
Refresh: string(rand.Bytes(5)),
}
}
truncAndCreate = func(t *testing.T) (*require.Assertions, *types.AuthOa2token) {
req := require.New(t)
req.NoError(s.TruncateAuthOa2tokens(ctx))
res := makeNew()
req.NoError(s.CreateAuthOa2token(ctx, res))
return req, res
}
)
t.Run("create", func(t *testing.T) {
authOa2token := makeNew()
req.NoError(s.CreateAuthOa2token(ctx, authOa2token))
})
t.Run("lookup by", func(t *testing.T) {
t.Run("access", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
fetched, err := s.LookupAuthOa2tokenByAccess(ctx, authOa2token.Access)
req.NoError(err)
req.NotNil(fetched)
})
t.Run("code", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
fetched, err := s.LookupAuthOa2tokenByCode(ctx, authOa2token.Code)
req.NoError(err)
req.NotNil(fetched)
})
t.Run("refresh", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
fetched, err := s.LookupAuthOa2tokenByRefresh(ctx, authOa2token.Refresh)
req.NoError(err)
req.NotNil(fetched)
})
})
t.Run("delete", func(t *testing.T) {
t.Run("access", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
err := s.DeleteAuthOA2TokenByRefresh(ctx, authOa2token.Access)
req.NoError(err)
})
t.Run("code", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
err := s.DeleteAuthOA2TokenByRefresh(ctx, authOa2token.Code)
req.NoError(err)
})
t.Run("refresh", func(t *testing.T) {
req, authOa2token := truncAndCreate(t)
err := s.DeleteAuthOA2TokenByRefresh(ctx, authOa2token.Refresh)
req.NoError(err)
})
})
}