MCPcopy Index your code
hub / github.com/tinyauthapp/tinyauth / TestOIDCController

Function TestOIDCController

internal/controller/oidc_controller_test.go:25–885  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestOIDCController(t *testing.T) {
26 tlog.NewTestLogger().Init()
27 tempDir := t.TempDir()
28
29 oidcServiceCfg := service.OIDCServiceConfig{
30 Clients: map[string]config.OIDCClientConfig{
31 "test": {
32 ClientID: "some-client-id",
33 ClientSecret: "some-client-secret",
34 TrustedRedirectURIs: []string{"https://test.example.com/callback"},
35 Name: "Test Client",
36 },
37 },
38 PrivateKeyPath: path.Join(tempDir, "key.pem"),
39 PublicKeyPath: path.Join(tempDir, "key.pub"),
40 Issuer: "https://tinyauth.example.com",
41 SessionExpiry: 500,
42 }
43
44 controllerCfg := controller.OIDCControllerConfig{}
45
46 simpleCtx := func(c *gin.Context) {
47 c.Set("context", &config.UserContext{
48 Username: "test",
49 Name: "Test User",
50 Email: "test@example.com",
51 IsLoggedIn: true,
52 Provider: "local",
53 })
54 c.Next()
55 }
56
57 type testCase struct {
58 description string
59 middlewares []gin.HandlerFunc
60 run func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder)
61 }
62
63 var tests []testCase
64
65 getTestByDescription := func(description string) (func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder), bool) {
66 for _, test := range tests {
67 if test.description == description {
68 return test.run, true
69 }
70 }
71 return nil, false
72 }
73
74 tests = []testCase{
75 {
76 description: "Ensure we can fetch the client",
77 middlewares: []gin.HandlerFunc{},
78 run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
79 req := httptest.NewRequest("GET", "/api/oidc/clients/some-client-id", nil)
80 router.ServeHTTP(recorder, req)
81 assert.Equal(t, 200, recorder.Code)
82 },

Callers

nothing calls this directly

Calls 10

SetupDatabaseMethod · 0.95
InitMethod · 0.95
SetupRoutesMethod · 0.95
NewTestLoggerFunction · 0.92
NewBootstrapAppFunction · 0.92
NewFunction · 0.92
NewOIDCServiceFunction · 0.92
NewOIDCControllerFunction · 0.92
CleanupMethod · 0.80
InitMethod · 0.45

Tested by

no test coverage detected