Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add possibility to override base Issuer #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions mockoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type MockOIDC struct {
ClientID string
ClientSecret string

IssuerBaseUrl string

AccessTTL time.Duration
RefreshTTL time.Duration

Expand Down Expand Up @@ -225,14 +227,27 @@ func (m *MockOIDC) Issuer() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl and the root path /oidc
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + IssuerBase
}

return m.Addr() + IssuerBase

}

// DiscoveryEndpoint returns the full `/.well-known/openid-configuration` URL
func (m *MockOIDC) DiscoveryEndpoint() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + DiscoveryEndpoint
}

return m.Addr() + DiscoveryEndpoint
}

Expand All @@ -241,6 +256,12 @@ func (m *MockOIDC) AuthorizationEndpoint() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + AuthorizationEndpoint
}

return m.Addr() + AuthorizationEndpoint
}

Expand All @@ -249,6 +270,12 @@ func (m *MockOIDC) TokenEndpoint() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + TokenEndpoint
}

return m.Addr() + TokenEndpoint
}

Expand All @@ -257,6 +284,12 @@ func (m *MockOIDC) UserinfoEndpoint() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + UserinfoEndpoint
}

return m.Addr() + UserinfoEndpoint
}

Expand All @@ -265,6 +298,12 @@ func (m *MockOIDC) JWKSEndpoint() string {
if m.Server == nil {
return ""
}

// Generate the Issue from IssuerBaseUrl
if m.IssuerBaseUrl != "" {
return m.IssuerBaseUrl + JWKSEndpoint
}

return m.Addr() + JWKSEndpoint
}

Expand Down
16 changes: 16 additions & 0 deletions mockoidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ func TestMockOIDC_Config(t *testing.T) {
assert.Equal(t, m.CodeChallengeMethodsSupported, cfg.CodeChallengeMethodsSupported)
}

func TestMockOIDC_ConfigBaseIssuer(t *testing.T) {
m, err := mockoidc.Run()
assert.NoError(t, err)
defer m.Shutdown()

m.IssuerBaseUrl = "https://idp.oidc.proxy.com"

cfg := m.Config()
assert.Equal(t, m.ClientID, cfg.ClientID)
assert.Equal(t, m.ClientSecret, cfg.ClientSecret)
assert.Equal(t, m.Issuer(), cfg.Issuer)
assert.Equal(t, m.AccessTTL, cfg.AccessTTL)
assert.Equal(t, m.RefreshTTL, cfg.RefreshTTL)
assert.Equal(t, m.CodeChallengeMethodsSupported, cfg.CodeChallengeMethodsSupported)
}

func TestMockOIDC_QueueError(t *testing.T) {
m, err := mockoidc.Run()
assert.NoError(t, err)
Expand Down