From 42ef46b74e0294c3dd5cf783fc41e3bcff411382 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Petersen" Date: Mon, 22 Apr 2024 16:36:14 -0400 Subject: [PATCH] expand TestUpstreamGitHubIdentityProvider --- .../resolved_github_provider.go | 20 ++-- .../oidctestutil/testgithubprovider.go | 91 ++++++++++++++++++- 2 files changed, 99 insertions(+), 12 deletions(-) diff --git a/internal/federationdomain/resolvedprovider/resolvedgithub/resolved_github_provider.go b/internal/federationdomain/resolvedprovider/resolvedgithub/resolved_github_provider.go index 3574d4e06..faca23e6b 100644 --- a/internal/federationdomain/resolvedprovider/resolvedgithub/resolved_github_provider.go +++ b/internal/federationdomain/resolvedprovider/resolvedgithub/resolved_github_provider.go @@ -70,8 +70,8 @@ func (p *FederationDomainResolvedGitHubIdentityProvider) ApplyIDPSpecificSession } func (p *FederationDomainResolvedGitHubIdentityProvider) UpstreamAuthorizeRedirectURL( - state *resolvedprovider.UpstreamAuthorizeRequestState, //nolint:all - downstreamIssuerURL string, //nolint:all + state *resolvedprovider.UpstreamAuthorizeRequestState, + downstreamIssuerURL string, ) (string, error) { // TODO: implement fmt.Printf("GithubResolvedIdentityProvider ~ UpstreamAuthorizeRedirectURL() called with state: %#v, downstreamIssuerURL %s", state, downstreamIssuerURL) @@ -80,8 +80,8 @@ func (p *FederationDomainResolvedGitHubIdentityProvider) UpstreamAuthorizeRedire func (p *FederationDomainResolvedGitHubIdentityProvider) Login( ctx context.Context, //nolint:all - submittedUsername string, //nolint:all - submittedPassword string, //nolint:all + submittedUsername string, + submittedPassword string, ) (*resolvedprovider.Identity, *resolvedprovider.IdentityLoginExtras, error) { // TODO: implement fmt.Printf("GithubResolvedIdentityProvider ~ Login() called with submittedUserName %s, submittedPassword %s", submittedUsername, submittedPassword) @@ -90,19 +90,19 @@ func (p *FederationDomainResolvedGitHubIdentityProvider) Login( func (p *FederationDomainResolvedGitHubIdentityProvider) LoginFromCallback( ctx context.Context, //nolint:all - authCode string, //nolint:all - pkce pkce.Code, //nolint:all - nonce nonce.Nonce, //nolint:all - redirectURI string, //nolint:all + authCode string, + pkce pkce.Code, + nonce nonce.Nonce, + redirectURI string, ) (*resolvedprovider.Identity, *resolvedprovider.IdentityLoginExtras, error) { // TODO: implement - fmt.Printf("GithubResolvedIdentityProvider ~ LoginFromCallback() called wtih authCode: %s, pkce: %#v, nonce: %#v, redirectURI: %s", authCode, pkce, nonce, redirectURI) + fmt.Printf("GithubResolvedIdentityProvider ~ LoginFromCallback() called with authCode: %s, pkce: %#v, nonce: %#v, redirectURI: %s", authCode, pkce, nonce, redirectURI) return nil, nil, nil } func (p *FederationDomainResolvedGitHubIdentityProvider) UpstreamRefresh( ctx context.Context, //nolint:all - identity *resolvedprovider.Identity, //nolint:all + identity *resolvedprovider.Identity, ) (refreshedIdentity *resolvedprovider.RefreshedIdentity, err error) { // TODO: implement fmt.Printf("GithubResolvedIdentityProvider ~ UpstreamRefresh() called with identity %#v", identity) diff --git a/internal/testutil/oidctestutil/testgithubprovider.go b/internal/testutil/oidctestutil/testgithubprovider.go index 361ae30df..5b985815b 100644 --- a/internal/testutil/oidctestutil/testgithubprovider.go +++ b/internal/testutil/oidctestutil/testgithubprovider.go @@ -4,19 +4,27 @@ package oidctestutil import ( + "net/http" + "k8s.io/apimachinery/pkg/types" + "go.pinniped.dev/generated/latest/apis/supervisor/idp/v1alpha1" "go.pinniped.dev/internal/federationdomain/upstreamprovider" "go.pinniped.dev/internal/idtransform" ) -// TODO: flesh this out. type TestUpstreamGitHubIdentityProviderBuilder struct { name string clientID string resourceUID types.UID displayNameForFederationDomain string transformsForFederationDomain *idtransform.TransformationPipeline + usernameAttribute v1alpha1.GitHubUsernameAttribute + groupNameAttribute v1alpha1.GitHubGroupNameAttribute + allowedOrganizations []string + organizationLoginPolicy v1alpha1.GitHubAllowedAuthOrganizationsPolicy + authorizationURL string + httpClient *http.Client } func (u *TestUpstreamGitHubIdentityProviderBuilder) WithName(value string) *TestUpstreamGitHubIdentityProviderBuilder { @@ -34,6 +42,41 @@ func (u *TestUpstreamGitHubIdentityProviderBuilder) WithClientID(value string) * return u } +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithDisplayNameForFederationDomain(value string) *TestUpstreamGitHubIdentityProviderBuilder { + u.displayNameForFederationDomain = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithUsernameAttribute(value v1alpha1.GitHubUsernameAttribute) *TestUpstreamGitHubIdentityProviderBuilder { + u.usernameAttribute = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithGroupNameAttribute(value v1alpha1.GitHubGroupNameAttribute) *TestUpstreamGitHubIdentityProviderBuilder { + u.groupNameAttribute = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithAllowedOrganizations(value []string) *TestUpstreamGitHubIdentityProviderBuilder { + u.allowedOrganizations = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithOrganizationLoginPolicy(value v1alpha1.GitHubAllowedAuthOrganizationsPolicy) *TestUpstreamGitHubIdentityProviderBuilder { + u.organizationLoginPolicy = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithAuthorizationURL(value string) *TestUpstreamGitHubIdentityProviderBuilder { + u.authorizationURL = value + return u +} + +func (u *TestUpstreamGitHubIdentityProviderBuilder) WithHttpClient(value *http.Client) *TestUpstreamGitHubIdentityProviderBuilder { + u.httpClient = value + return u +} + func (u *TestUpstreamGitHubIdentityProviderBuilder) Build() *TestUpstreamGitHubIdentityProvider { if u.displayNameForFederationDomain == "" { // default it to the CR name @@ -43,13 +86,18 @@ func (u *TestUpstreamGitHubIdentityProviderBuilder) Build() *TestUpstreamGitHubI // default to an empty pipeline u.transformsForFederationDomain = idtransform.NewTransformationPipeline() } - // TODO: flesh this out. return &TestUpstreamGitHubIdentityProvider{ Name: u.name, ResourceUID: u.resourceUID, ClientID: u.clientID, DisplayNameForFederationDomain: u.displayNameForFederationDomain, TransformsForFederationDomain: u.transformsForFederationDomain, + UsernameAttribute: u.usernameAttribute, + GroupNameAttribute: u.groupNameAttribute, + AllowedOrganizations: u.allowedOrganizations, + OrganizationLoginPolicy: u.organizationLoginPolicy, + AuthorizationURL: u.authorizationURL, + HttpClient: u.httpClient, } } @@ -62,8 +110,15 @@ type TestUpstreamGitHubIdentityProvider struct { Name string ClientID string ResourceUID types.UID + Host string DisplayNameForFederationDomain string TransformsForFederationDomain *idtransform.TransformationPipeline + UsernameAttribute v1alpha1.GitHubUsernameAttribute + GroupNameAttribute v1alpha1.GitHubGroupNameAttribute + AllowedOrganizations []string + OrganizationLoginPolicy v1alpha1.GitHubAllowedAuthOrganizationsPolicy + AuthorizationURL string + HttpClient *http.Client } var _ upstreamprovider.UpstreamGithubIdentityProviderI = &TestUpstreamGitHubIdentityProvider{} @@ -75,3 +130,35 @@ func (u *TestUpstreamGitHubIdentityProvider) GetResourceUID() types.UID { func (u *TestUpstreamGitHubIdentityProvider) GetName() string { return u.Name } + +func (u *TestUpstreamGitHubIdentityProvider) GetHost() string { + return u.Host +} + +func (u *TestUpstreamGitHubIdentityProvider) GetClientID() string { + return u.ClientID +} + +func (u *TestUpstreamGitHubIdentityProvider) GetUsernameAttribute() v1alpha1.GitHubUsernameAttribute { + return u.UsernameAttribute +} + +func (u *TestUpstreamGitHubIdentityProvider) GetGroupNameAttribute() v1alpha1.GitHubGroupNameAttribute { + return u.GroupNameAttribute +} + +func (u *TestUpstreamGitHubIdentityProvider) GetAllowedOrganizations() []string { + return u.AllowedOrganizations +} + +func (u *TestUpstreamGitHubIdentityProvider) GetOrganizationLoginPolicy() v1alpha1.GitHubAllowedAuthOrganizationsPolicy { + return u.OrganizationLoginPolicy +} + +func (u *TestUpstreamGitHubIdentityProvider) GetAuthorizationURL() string { + return u.AuthorizationURL +} + +func (u *TestUpstreamGitHubIdentityProvider) GetHttpClient() *http.Client { + return u.HttpClient +}