2023-06-05 21:40:39 +00:00
// Copyright 2020-2023 the Pinniped contributors. All Rights Reserved.
2020-10-09 00:40:58 +00:00
// SPDX-License-Identifier: Apache-2.0
package supervisorconfig
import (
"context"
2020-10-09 14:39:17 +00:00
"errors"
2021-02-05 17:56:05 +00:00
"fmt"
2020-10-23 23:25:44 +00:00
"net/url"
2020-10-09 14:39:17 +00:00
"reflect"
"sync"
2020-10-09 00:40:58 +00:00
"testing"
"time"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/require"
2023-07-05 20:33:21 +00:00
corev1 "k8s.io/api/core/v1"
2020-10-09 00:40:58 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020-10-09 14:39:17 +00:00
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
coretesting "k8s.io/client-go/testing"
2021-12-10 22:22:36 +00:00
clocktesting "k8s.io/utils/clock/testing"
2020-10-09 00:40:58 +00:00
2023-07-05 20:33:21 +00:00
configv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1"
idpv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/idp/v1alpha1"
2021-02-16 19:00:08 +00:00
pinnipedfake "go.pinniped.dev/generated/latest/client/supervisor/clientset/versioned/fake"
pinnipedinformers "go.pinniped.dev/generated/latest/client/supervisor/informers/externalversions"
2020-10-09 00:40:58 +00:00
"go.pinniped.dev/internal/controllerlib"
2023-06-22 22:12:33 +00:00
"go.pinniped.dev/internal/federationdomain/federationdomainproviders"
2020-10-09 00:40:58 +00:00
"go.pinniped.dev/internal/testutil"
)
2023-07-05 20:33:21 +00:00
func TestFederationDomainWatcherControllerInformerFilters ( t * testing . T ) {
t . Parallel ( )
federationDomainInformer := pinnipedinformers . NewSharedInformerFactoryWithOptions ( nil , 0 ) . Config ( ) . V1alpha1 ( ) . FederationDomains ( )
oidcIdentityProviderInformer := pinnipedinformers . NewSharedInformerFactoryWithOptions ( nil , 0 ) . IDP ( ) . V1alpha1 ( ) . OIDCIdentityProviders ( )
ldapIdentityProviderInformer := pinnipedinformers . NewSharedInformerFactoryWithOptions ( nil , 0 ) . IDP ( ) . V1alpha1 ( ) . LDAPIdentityProviders ( )
adIdentityProviderInformer := pinnipedinformers . NewSharedInformerFactoryWithOptions ( nil , 0 ) . IDP ( ) . V1alpha1 ( ) . ActiveDirectoryIdentityProviders ( )
tests := [ ] struct {
name string
obj metav1 . Object
informer controllerlib . InformerGetter
wantAdd bool
wantUpdate bool
wantDelete bool
} {
{
name : "any FederationDomain changes" ,
obj : & configv1alpha1 . FederationDomain { } ,
informer : federationDomainInformer ,
wantAdd : true ,
wantUpdate : true ,
wantDelete : true ,
} ,
{
name : "any OIDCIdentityProvider adds or deletes, but updates are ignored" ,
obj : & idpv1alpha1 . OIDCIdentityProvider { } ,
informer : oidcIdentityProviderInformer ,
wantAdd : true ,
wantUpdate : false ,
wantDelete : true ,
} ,
{
name : "any LDAPIdentityProvider adds or deletes, but updates are ignored" ,
obj : & idpv1alpha1 . LDAPIdentityProvider { } ,
informer : ldapIdentityProviderInformer ,
wantAdd : true ,
wantUpdate : false ,
wantDelete : true ,
} ,
{
name : "any ActiveDirectoryIdentityProvider adds or deletes, but updates are ignored" ,
obj : & idpv1alpha1 . ActiveDirectoryIdentityProvider { } ,
informer : adIdentityProviderInformer ,
wantAdd : true ,
wantUpdate : false ,
wantDelete : true ,
} ,
}
for _ , test := range tests {
test := test
t . Run ( test . name , func ( t * testing . T ) {
t . Parallel ( )
withInformer := testutil . NewObservableWithInformerOption ( )
NewFederationDomainWatcherController (
2020-10-09 00:40:58 +00:00
nil ,
nil ,
nil ,
2020-12-17 19:34:49 +00:00
federationDomainInformer ,
2023-06-05 21:40:39 +00:00
oidcIdentityProviderInformer ,
ldapIdentityProviderInformer ,
adIdentityProviderInformer ,
2023-07-05 20:33:21 +00:00
withInformer . WithInformer , // make it possible to observe the behavior of the Filters
2020-10-09 00:40:58 +00:00
)
2023-07-05 20:33:21 +00:00
unrelatedObj := corev1 . Secret { }
filter := withInformer . GetFilterForInformer ( test . informer )
require . Equal ( t , test . wantAdd , filter . Add ( test . obj ) )
require . Equal ( t , test . wantUpdate , filter . Update ( & unrelatedObj , test . obj ) )
require . Equal ( t , test . wantUpdate , filter . Update ( test . obj , & unrelatedObj ) )
require . Equal ( t , test . wantDelete , filter . Delete ( test . obj ) )
2020-10-09 00:40:58 +00:00
} )
2023-07-05 20:33:21 +00:00
}
2020-10-09 00:40:58 +00:00
}
2023-06-13 21:20:39 +00:00
type fakeFederationDomainsSetter struct {
SetFederationDomainsWasCalled bool
2023-06-22 20:12:50 +00:00
FederationDomainsReceived [ ] * federationdomainproviders . FederationDomainIssuer
2020-10-09 00:40:58 +00:00
}
2023-06-22 20:12:50 +00:00
func ( f * fakeFederationDomainsSetter ) SetFederationDomains ( federationDomains ... * federationdomainproviders . FederationDomainIssuer ) {
2023-06-13 21:20:39 +00:00
f . SetFederationDomainsWasCalled = true
2020-12-16 22:27:09 +00:00
f . FederationDomainsReceived = federationDomains
2020-10-09 00:40:58 +00:00
}
2023-07-05 20:33:21 +00:00
func TestTestFederationDomainWatcherControllerSync ( t * testing . T ) {
2020-10-09 00:40:58 +00:00
spec . Run ( t , "Sync" , func ( t * testing . T , when spec . G , it spec . S ) {
2020-10-09 14:39:17 +00:00
const namespace = "some-namespace"
2020-10-09 00:40:58 +00:00
var r * require . Assertions
var subject controllerlib . Controller
2023-06-05 21:40:39 +00:00
var pinnipedInformerClient * pinnipedfake . Clientset
var pinnipedInformers pinnipedinformers . SharedInformerFactory
2020-10-09 00:40:58 +00:00
var pinnipedAPIClient * pinnipedfake . Clientset
2021-03-05 01:25:43 +00:00
var cancelContext context . Context
var cancelContextCancelFunc context . CancelFunc
2020-10-09 00:40:58 +00:00
var syncContext * controllerlib . Context
var frozenNow time . Time
2023-06-30 20:43:40 +00:00
var frozenMetav1Now metav1 . Time
2023-06-13 21:20:39 +00:00
var federationDomainsSetter * fakeFederationDomainsSetter
2020-12-16 22:27:09 +00:00
var federationDomainGVR schema . GroupVersionResource
2023-07-05 20:33:21 +00:00
var allHappyConditions func ( issuer string , time metav1 . Time , observedGeneration int64 ) [ ] configv1alpha1 . Condition
var happyReadyCondition func ( issuer string , time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition
2023-06-30 20:43:40 +00:00
var happyIssuerIsUniqueCondition ,
unknownIssuerIsUniqueCondition ,
sadIssuerIsUniqueCondition ,
happyOneTLSSecretPerIssuerHostnameCondition ,
unknownOneTLSSecretPerIssuerHostnameCondition ,
sadOneTLSSecretPerIssuerHostnameCondition ,
happyIssuerURLValidCondition ,
sadIssuerURLValidConditionCannotHaveQuery ,
sadIssuerURLValidConditionCannotParse ,
2023-07-05 20:33:21 +00:00
sadReadyCondition func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition
2020-10-09 00:40:58 +00:00
// Defer starting the informers until the last possible moment so that the
// nested Before's can keep adding things to the informer caches.
var startInformersAndController = func ( ) {
// Set this at the last second to allow for injection of server override.
2020-12-16 22:27:09 +00:00
subject = NewFederationDomainWatcherController (
2023-06-13 21:20:39 +00:00
federationDomainsSetter ,
2021-12-10 22:22:36 +00:00
clocktesting . NewFakeClock ( frozenNow ) ,
2020-10-09 00:40:58 +00:00
pinnipedAPIClient ,
2023-06-05 21:40:39 +00:00
pinnipedInformers . Config ( ) . V1alpha1 ( ) . FederationDomains ( ) ,
pinnipedInformers . IDP ( ) . V1alpha1 ( ) . OIDCIdentityProviders ( ) ,
pinnipedInformers . IDP ( ) . V1alpha1 ( ) . LDAPIdentityProviders ( ) ,
pinnipedInformers . IDP ( ) . V1alpha1 ( ) . ActiveDirectoryIdentityProviders ( ) ,
2020-10-09 00:40:58 +00:00
controllerlib . WithInformer ,
)
// Set this at the last second to support calling subject.Name().
syncContext = & controllerlib . Context {
2021-03-05 01:25:43 +00:00
Context : cancelContext ,
2020-10-09 00:40:58 +00:00
Name : subject . Name ( ) ,
Key : controllerlib . Key {
2020-10-09 14:39:17 +00:00
Namespace : namespace ,
2020-10-09 00:40:58 +00:00
Name : "config-name" ,
} ,
}
// Must start informers before calling TestRunSynchronously()
2023-06-05 21:40:39 +00:00
pinnipedInformers . Start ( cancelContext . Done ( ) )
2020-10-09 00:40:58 +00:00
controllerlib . TestRunSynchronously ( t , subject )
}
it . Before ( func ( ) {
r = require . New ( t )
2023-06-13 21:20:39 +00:00
federationDomainsSetter = & fakeFederationDomainsSetter { }
2020-10-09 00:40:58 +00:00
frozenNow = time . Date ( 2020 , time . September , 23 , 7 , 42 , 0 , 0 , time . Local )
2021-03-05 01:25:43 +00:00
cancelContext , cancelContextCancelFunc = context . WithCancel ( context . Background ( ) )
2020-10-09 00:40:58 +00:00
2023-06-05 21:40:39 +00:00
pinnipedInformerClient = pinnipedfake . NewSimpleClientset ( )
pinnipedInformers = pinnipedinformers . NewSharedInformerFactory ( pinnipedInformerClient , 0 )
2020-10-09 00:40:58 +00:00
pinnipedAPIClient = pinnipedfake . NewSimpleClientset ( )
2020-10-09 14:39:17 +00:00
2020-12-16 22:27:09 +00:00
federationDomainGVR = schema . GroupVersionResource {
2023-07-05 20:33:21 +00:00
Group : configv1alpha1 . SchemeGroupVersion . Group ,
Version : configv1alpha1 . SchemeGroupVersion . Version ,
2020-12-16 22:27:09 +00:00
Resource : "federationdomains" ,
2020-10-09 14:39:17 +00:00
}
2023-06-30 20:43:40 +00:00
frozenMetav1Now = metav1 . NewTime ( frozenNow )
2023-07-05 20:33:21 +00:00
happyReadyCondition = func ( issuer string , time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "Ready" ,
Status : "True" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "Success" ,
Message : fmt . Sprintf ( "the FederationDomain is ready and its endpoints are available: " +
"the discovery endpoint is %s/.well-known/openid-configuration" , issuer ) ,
}
}
2023-07-05 20:33:21 +00:00
sadReadyCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "Ready" ,
Status : "False" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "NotReady" ,
Message : "the FederationDomain is not ready: see other conditions for details" ,
}
}
2023-07-05 20:33:21 +00:00
happyIssuerIsUniqueCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerIsUnique" ,
Status : "True" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "Success" ,
Message : "spec.issuer is unique among all FederationDomains" ,
}
}
2023-07-05 20:33:21 +00:00
unknownIssuerIsUniqueCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerIsUnique" ,
Status : "Unknown" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "UnableToValidate" ,
Message : "unable to check if spec.issuer is unique among all FederationDomains because URL cannot be parsed" ,
}
}
2023-07-05 20:33:21 +00:00
sadIssuerIsUniqueCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerIsUnique" ,
Status : "False" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "DuplicateIssuer" ,
Message : "multiple FederationDomains have the same spec.issuer URL: these URLs must be unique (can use different hosts or paths)" ,
}
}
2023-07-05 20:33:21 +00:00
happyOneTLSSecretPerIssuerHostnameCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "OneTLSSecretPerIssuerHostname" ,
Status : "True" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "Success" ,
Message : "all FederationDomains are using the same TLS secret when using the same hostname in the spec.issuer URL" ,
}
}
2023-07-05 20:33:21 +00:00
unknownOneTLSSecretPerIssuerHostnameCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "OneTLSSecretPerIssuerHostname" ,
Status : "Unknown" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "UnableToValidate" ,
Message : "unable to check if all FederationDomains are using the same TLS secret when using the same hostname in the spec.issuer URL because URL cannot be parsed" ,
}
}
2023-07-05 20:33:21 +00:00
sadOneTLSSecretPerIssuerHostnameCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "OneTLSSecretPerIssuerHostname" ,
Status : "False" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "DifferentSecretRefsFound" ,
Message : "when different FederationDomains are using the same hostname in the spec.issuer URL then they must also use the same TLS secretRef: different secretRefs found" ,
}
}
2023-07-05 20:33:21 +00:00
happyIssuerURLValidCondition = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerURLValid" ,
Status : "True" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "Success" ,
Message : "spec.issuer is a valid URL" ,
}
}
2023-07-05 20:33:21 +00:00
sadIssuerURLValidConditionCannotHaveQuery = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerURLValid" ,
Status : "False" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "InvalidIssuerURL" ,
Message : "issuer must not have query" ,
}
}
2023-07-05 20:33:21 +00:00
sadIssuerURLValidConditionCannotParse = func ( time metav1 . Time , observedGeneration int64 ) configv1alpha1 . Condition {
return configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
Type : "IssuerURLValid" ,
Status : "False" ,
ObservedGeneration : observedGeneration ,
LastTransitionTime : time ,
Reason : "InvalidIssuerURL" ,
Message : ` could not parse issuer as URL: parse ":/host//path": missing protocol scheme ` ,
}
}
2023-07-05 20:33:21 +00:00
allHappyConditions = func ( issuer string , time metav1 . Time , observedGeneration int64 ) [ ] configv1alpha1 . Condition {
return [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
happyIssuerIsUniqueCondition ( time , observedGeneration ) ,
happyIssuerURLValidCondition ( time , observedGeneration ) ,
happyOneTLSSecretPerIssuerHostnameCondition ( time , observedGeneration ) ,
happyReadyCondition ( issuer , time , observedGeneration ) ,
}
}
2020-10-09 00:40:58 +00:00
} )
it . After ( func ( ) {
2021-03-05 01:25:43 +00:00
cancelContextCancelFunc ( )
2020-10-09 00:40:58 +00:00
} )
2020-12-16 22:27:09 +00:00
when ( "there are some valid FederationDomains in the informer" , func ( ) {
2020-10-09 14:39:17 +00:00
var (
2023-07-05 20:33:21 +00:00
federationDomain1 * configv1alpha1 . FederationDomain
federationDomain2 * configv1alpha1 . FederationDomain
2020-10-09 14:39:17 +00:00
)
2020-10-09 00:40:58 +00:00
it . Before ( func ( ) {
2023-07-05 20:33:21 +00:00
federationDomain1 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "config1" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://issuer1.com" } ,
2020-10-09 00:40:58 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomain1 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomain1 ) )
2020-10-09 00:40:58 +00:00
2023-07-05 20:33:21 +00:00
federationDomain2 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "config2" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://issuer2.com" } ,
2020-10-09 00:40:58 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomain2 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomain2 ) )
2020-10-09 00:40:58 +00:00
} )
2023-06-13 21:20:39 +00:00
it ( "calls the FederationDomainsSetter" , func ( ) {
2020-10-09 00:40:58 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-06-22 20:12:50 +00:00
fd1 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain1 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-22 20:12:50 +00:00
fd2 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain2 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-09 14:39:17 +00:00
r . ElementsMatch (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
fd1 ,
fd2 ,
2020-10-09 14:39:17 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-09 14:39:17 +00:00
)
} )
2023-06-30 20:43:40 +00:00
it ( "updates the status to ready in the FederationDomains" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-07-05 20:33:21 +00:00
federationDomain1 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain1 . Status . Conditions = allHappyConditions ( federationDomain1 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomain2 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain2 . Status . Conditions = allHappyConditions ( federationDomain2 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain1 . Namespace ,
federationDomain1 ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain2 . Namespace ,
federationDomain2 ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
2020-12-16 22:27:09 +00:00
when ( "one FederationDomain is already up to date" , func ( ) {
2020-10-09 14:39:17 +00:00
it . Before ( func ( ) {
2023-07-05 20:33:21 +00:00
federationDomain1 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain1 . Status . Conditions = allHappyConditions ( federationDomain1 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Update ( federationDomainGVR , federationDomain1 , federationDomain1 . Namespace ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Update ( federationDomainGVR , federationDomain1 , federationDomain1 . Namespace ) )
2020-10-09 14:39:17 +00:00
} )
2020-12-16 22:27:09 +00:00
it ( "only updates the out-of-date FederationDomain" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-07-05 20:33:21 +00:00
federationDomain2 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain2 . Status . Conditions = allHappyConditions ( federationDomain2 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain2 . Namespace ,
federationDomain2 ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
2023-06-13 21:20:39 +00:00
it ( "calls the FederationDomainsSetter with both FederationDomain's" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2020-10-09 00:40:58 +00:00
2023-06-22 20:12:50 +00:00
fd1 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain1 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-22 20:12:50 +00:00
fd2 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain2 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-09 14:39:17 +00:00
r . ElementsMatch (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
fd1 ,
fd2 ,
2020-10-09 14:39:17 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-09 14:39:17 +00:00
)
} )
} )
2023-06-30 20:43:40 +00:00
when ( "updating only one FederationDomain fails" , func ( ) {
2020-10-09 14:39:17 +00:00
it . Before ( func ( ) {
once := sync . Once { }
pinnipedAPIClient . PrependReactor (
"update" ,
2020-12-16 22:27:09 +00:00
"federationdomains" ,
2020-10-09 14:39:17 +00:00
func ( _ coretesting . Action ) ( bool , runtime . Object , error ) {
var err error
once . Do ( func ( ) {
err = errors . New ( "some update error" )
} )
return true , nil , err
} ,
)
} )
2023-06-13 21:20:39 +00:00
it ( "sets the FederationDomain that it could actually update in the API" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
2021-02-05 17:56:05 +00:00
r . EqualError ( err , "could not update status: some update error" )
2020-10-09 14:39:17 +00:00
2023-06-22 20:12:50 +00:00
fd1 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain1 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-22 20:12:50 +00:00
fd2 , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain2 . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
r . Len ( federationDomainsSetter . FederationDomainsReceived , 1 )
2020-10-09 14:39:17 +00:00
r . True (
2023-06-13 21:20:39 +00:00
reflect . DeepEqual ( federationDomainsSetter . FederationDomainsReceived [ 0 ] , fd1 ) ||
reflect . DeepEqual ( federationDomainsSetter . FederationDomainsReceived [ 0 ] , fd2 ) ,
2020-10-09 14:39:17 +00:00
)
} )
it ( "returns an error" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
2021-02-05 17:56:05 +00:00
r . EqualError ( err , "could not update status: some update error" )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomain1 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain1 . Status . Conditions = allHappyConditions ( federationDomain1 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomain2 . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain2 . Status . Conditions = allHappyConditions ( federationDomain2 . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain1 . Namespace ,
federationDomain1 ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain2 . Namespace ,
federationDomain2 ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
} )
} )
2020-12-16 22:27:09 +00:00
when ( "there are errors updating the FederationDomains" , func ( ) {
2020-10-09 14:39:17 +00:00
var (
2023-07-05 20:33:21 +00:00
federationDomain * configv1alpha1 . FederationDomain
2020-10-09 14:39:17 +00:00
)
it . Before ( func ( ) {
2023-07-05 20:33:21 +00:00
federationDomain = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "config" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://issuer.com" } ,
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomain ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomain ) )
2020-10-09 00:40:58 +00:00
} )
2023-06-30 20:43:40 +00:00
when ( "updating the FederationDomain fails" , func ( ) {
2020-10-09 14:39:17 +00:00
it . Before ( func ( ) {
pinnipedAPIClient . PrependReactor (
"update" ,
2020-12-16 22:27:09 +00:00
"federationdomains" ,
2020-10-09 14:39:17 +00:00
func ( _ coretesting . Action ) ( bool , runtime . Object , error ) {
return true , nil , errors . New ( "some update error" )
} ,
)
} )
it ( "returns an error" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
2021-02-05 17:56:05 +00:00
r . EqualError ( err , "could not update status: some update error" )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain . Status . Conditions = allHappyConditions ( federationDomain . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain . Namespace ,
federationDomain ,
2020-10-09 14:39:17 +00:00
) ,
}
2023-06-30 20:43:40 +00:00
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
2020-10-09 14:39:17 +00:00
} )
2020-10-09 00:40:58 +00:00
} )
} )
2020-12-16 22:27:09 +00:00
when ( "there are both valid and invalid FederationDomains in the informer" , func ( ) {
2020-10-09 14:39:17 +00:00
var (
2023-07-05 20:33:21 +00:00
validFederationDomain * configv1alpha1 . FederationDomain
invalidFederationDomain * configv1alpha1 . FederationDomain
2020-10-09 14:39:17 +00:00
)
it . Before ( func ( ) {
2023-07-05 20:33:21 +00:00
validFederationDomain = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "valid-config" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://valid-issuer.com" } ,
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( validFederationDomain ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( validFederationDomain ) )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
invalidFederationDomain = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "invalid-config" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://invalid-issuer.com?some=query" } ,
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( invalidFederationDomain ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( invalidFederationDomain ) )
2020-10-09 14:39:17 +00:00
} )
2023-06-13 21:20:39 +00:00
it ( "calls the FederationDomainsSetter with the valid FederationDomain" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-06-22 20:12:50 +00:00
validFederationDomain , err := federationdomainproviders . NewFederationDomainIssuer ( validFederationDomain . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-09 14:39:17 +00:00
r . Equal (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
validFederationDomain ,
2020-10-09 14:39:17 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-09 14:39:17 +00:00
)
} )
2023-06-30 20:43:40 +00:00
it ( "updates the status in each FederationDomain" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-07-05 20:33:21 +00:00
validFederationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
validFederationDomain . Status . Conditions = allHappyConditions ( validFederationDomain . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
invalidFederationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseError
invalidFederationDomain . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
happyIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
sadIssuerURLValidConditionCannotHaveQuery ( frozenMetav1Now , 123 ) ,
happyOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
invalidFederationDomain . Namespace ,
invalidFederationDomain ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
validFederationDomain . Namespace ,
validFederationDomain ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
2023-06-30 20:43:40 +00:00
when ( "updating only the invalid FederationDomain fails" , func ( ) {
2020-10-09 14:39:17 +00:00
it . Before ( func ( ) {
pinnipedAPIClient . PrependReactor (
"update" ,
2020-12-16 22:27:09 +00:00
"federationdomains" ,
2020-10-09 14:39:17 +00:00
func ( action coretesting . Action ) ( bool , runtime . Object , error ) {
updateAction := action . ( coretesting . UpdateActionImpl )
2023-07-05 20:33:21 +00:00
federationDomain := updateAction . Object . ( * configv1alpha1 . FederationDomain )
2020-12-17 19:34:49 +00:00
if federationDomain . Name == validFederationDomain . Name {
2020-10-09 14:39:17 +00:00
return true , nil , nil
}
return true , nil , errors . New ( "some update error" )
} ,
)
} )
2023-06-13 21:20:39 +00:00
it ( "sets the FederationDomain that it could actually update in the API" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
2021-02-05 17:56:05 +00:00
r . EqualError ( err , "could not update status: some update error" )
2020-10-09 14:39:17 +00:00
2023-06-22 20:12:50 +00:00
validFederationDomain , err := federationdomainproviders . NewFederationDomainIssuer ( validFederationDomain . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-09 14:39:17 +00:00
r . Equal (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
validFederationDomain ,
2020-10-09 14:39:17 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-09 14:39:17 +00:00
)
} )
it ( "returns an error" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
2021-02-05 17:56:05 +00:00
r . EqualError ( err , "could not update status: some update error" )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
validFederationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
validFederationDomain . Status . Conditions = allHappyConditions ( validFederationDomain . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
invalidFederationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseError
invalidFederationDomain . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
happyIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
sadIssuerURLValidConditionCannotHaveQuery ( frozenMetav1Now , 123 ) ,
happyOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
invalidFederationDomain . Namespace ,
invalidFederationDomain ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
validFederationDomain . Namespace ,
validFederationDomain ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
} )
2020-10-09 00:40:58 +00:00
} )
2020-12-16 22:27:09 +00:00
when ( "there are FederationDomains with duplicate issuer names in the informer" , func ( ) {
2020-10-09 14:39:17 +00:00
var (
2023-07-05 20:33:21 +00:00
federationDomainDuplicate1 * configv1alpha1 . FederationDomain
federationDomainDuplicate2 * configv1alpha1 . FederationDomain
federationDomain * configv1alpha1 . FederationDomain
2020-10-09 14:39:17 +00:00
)
it . Before ( func ( ) {
2020-10-23 23:25:44 +00:00
// Hostnames are case-insensitive, so consider them to be duplicates if they only differ by case.
// Paths are case-sensitive, so having a path that differs only by case makes a new issuer.
2023-07-05 20:33:21 +00:00
federationDomainDuplicate1 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "duplicate1" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://iSSueR-duPlicAte.cOm/a" } ,
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainDuplicate1 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainDuplicate1 ) )
2023-07-05 20:33:21 +00:00
federationDomainDuplicate2 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "duplicate2" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://issuer-duplicate.com/a" } ,
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainDuplicate2 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainDuplicate2 ) )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomain = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "not-duplicate" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec { Issuer : "https://issuer-duplicate.com/A" } , // different path
2020-10-09 14:39:17 +00:00
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomain ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomain ) )
2020-10-09 14:39:17 +00:00
} )
2023-06-13 21:20:39 +00:00
it ( "calls the FederationDomainsSetter with the non-duplicate" , func ( ) {
2020-10-09 14:39:17 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-06-22 20:12:50 +00:00
nonDuplicateFederationDomain , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomain . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-09 14:39:17 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-09 14:39:17 +00:00
r . Equal (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
nonDuplicateFederationDomain ,
2020-10-09 14:39:17 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-09 14:39:17 +00:00
)
} )
it ( "updates the statuses" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-07-05 20:33:21 +00:00
federationDomain . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomain . Status . Conditions = allHappyConditions ( federationDomain . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomainDuplicate1 . Status . Phase = configv1alpha1 . FederationDomainPhaseError
federationDomainDuplicate1 . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
sadIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
happyIssuerURLValidCondition ( frozenMetav1Now , 123 ) ,
happyOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-09 14:39:17 +00:00
2023-07-05 20:33:21 +00:00
federationDomainDuplicate2 . Status . Phase = configv1alpha1 . FederationDomainPhaseError
federationDomainDuplicate2 . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
sadIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
happyIssuerURLValidCondition ( frozenMetav1Now , 123 ) ,
happyOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-09 14:39:17 +00:00
expectedActions := [ ] coretesting . Action {
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomainDuplicate1 . Namespace ,
federationDomainDuplicate1 ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomainDuplicate2 . Namespace ,
federationDomainDuplicate2 ,
2020-10-09 14:39:17 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomain . Namespace ,
federationDomain ,
2020-10-09 14:39:17 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
2020-10-09 00:40:58 +00:00
} )
2020-12-16 22:27:09 +00:00
when ( "there are FederationDomains with the same issuer DNS hostname using different secretNames" , func ( ) {
2020-10-23 23:25:44 +00:00
var (
2023-07-05 20:33:21 +00:00
federationDomainSameIssuerAddress1 * configv1alpha1 . FederationDomain
federationDomainSameIssuerAddress2 * configv1alpha1 . FederationDomain
federationDomainDifferentIssuerAddress * configv1alpha1 . FederationDomain
federationDomainWithInvalidIssuerURL * configv1alpha1 . FederationDomain
2020-10-23 23:25:44 +00:00
)
it . Before ( func ( ) {
2023-07-05 20:33:21 +00:00
federationDomainSameIssuerAddress1 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "fd1" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec {
2020-11-02 22:55:29 +00:00
Issuer : "https://iSSueR-duPlicAte-adDress.cOm/path1" ,
2023-07-05 20:33:21 +00:00
TLS : & configv1alpha1 . FederationDomainTLSSpec { SecretName : "secret1" } ,
2020-10-23 23:25:44 +00:00
} ,
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainSameIssuerAddress1 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainSameIssuerAddress1 ) )
2023-07-05 20:33:21 +00:00
federationDomainSameIssuerAddress2 = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "fd2" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec {
2020-10-27 00:03:26 +00:00
// Validation treats these as the same DNS hostname even though they have different port numbers,
// because SNI information on the incoming requests is not going to include port numbers.
2020-11-02 22:55:29 +00:00
Issuer : "https://issuer-duplicate-address.com:1234/path2" ,
2023-07-05 20:33:21 +00:00
TLS : & configv1alpha1 . FederationDomainTLSSpec { SecretName : "secret2" } ,
2020-10-23 23:25:44 +00:00
} ,
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainSameIssuerAddress2 ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainSameIssuerAddress2 ) )
2020-10-23 23:25:44 +00:00
2023-07-05 20:33:21 +00:00
federationDomainDifferentIssuerAddress = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "differentIssuerAddressFederationDomain" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec {
2020-11-02 22:55:29 +00:00
Issuer : "https://issuer-not-duplicate.com" ,
2023-07-05 20:33:21 +00:00
TLS : & configv1alpha1 . FederationDomainTLSSpec { SecretName : "secret1" } ,
2020-10-23 23:25:44 +00:00
} ,
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainDifferentIssuerAddress ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainDifferentIssuerAddress ) )
2020-10-23 23:25:44 +00:00
// Also add one with a URL that cannot be parsed to make sure that the error handling
// for the duplicate issuers and secret names are not confused by invalid URLs.
invalidIssuerURL := ":/host//path"
_ , err := url . Parse ( invalidIssuerURL ) //nolint:staticcheck // Yes, this URL is intentionally invalid.
r . Error ( err )
2023-07-05 20:33:21 +00:00
federationDomainWithInvalidIssuerURL = & configv1alpha1 . FederationDomain {
2023-06-30 20:43:40 +00:00
ObjectMeta : metav1 . ObjectMeta { Name : "invalidIssuerURLFederationDomain" , Namespace : namespace , Generation : 123 } ,
2023-07-05 20:33:21 +00:00
Spec : configv1alpha1 . FederationDomainSpec {
2020-11-02 22:55:29 +00:00
Issuer : invalidIssuerURL ,
2023-07-05 20:33:21 +00:00
TLS : & configv1alpha1 . FederationDomainTLSSpec { SecretName : "secret1" } ,
2020-10-23 23:25:44 +00:00
} ,
}
2020-12-16 22:27:09 +00:00
r . NoError ( pinnipedAPIClient . Tracker ( ) . Add ( federationDomainWithInvalidIssuerURL ) )
2023-06-05 21:40:39 +00:00
r . NoError ( pinnipedInformerClient . Tracker ( ) . Add ( federationDomainWithInvalidIssuerURL ) )
2020-10-23 23:25:44 +00:00
} )
2023-06-13 21:20:39 +00:00
it ( "calls the FederationDomainsSetter with the non-duplicate" , func ( ) {
2020-10-23 23:25:44 +00:00
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-06-22 20:12:50 +00:00
nonDuplicateFederationDomain , err := federationdomainproviders . NewFederationDomainIssuer ( federationDomainDifferentIssuerAddress . Spec . Issuer , [ ] * federationdomainproviders . FederationDomainIdentityProvider { } )
2020-10-23 23:25:44 +00:00
r . NoError ( err )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
2020-10-23 23:25:44 +00:00
r . Equal (
2023-06-22 20:12:50 +00:00
[ ] * federationdomainproviders . FederationDomainIssuer {
2023-06-13 21:20:39 +00:00
nonDuplicateFederationDomain ,
2020-10-23 23:25:44 +00:00
} ,
2023-06-13 21:20:39 +00:00
federationDomainsSetter . FederationDomainsReceived ,
2020-10-23 23:25:44 +00:00
)
} )
it ( "updates the statuses" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
2023-07-05 20:33:21 +00:00
federationDomainDifferentIssuerAddress . Status . Phase = configv1alpha1 . FederationDomainPhaseReady
2023-06-30 20:43:40 +00:00
federationDomainDifferentIssuerAddress . Status . Conditions = allHappyConditions ( federationDomainDifferentIssuerAddress . Spec . Issuer , frozenMetav1Now , 123 )
2020-10-23 23:25:44 +00:00
2023-07-05 20:33:21 +00:00
federationDomainSameIssuerAddress1 . Status . Phase = configv1alpha1 . FederationDomainPhaseError
federationDomainSameIssuerAddress1 . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
happyIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
happyIssuerURLValidCondition ( frozenMetav1Now , 123 ) ,
sadOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-23 23:25:44 +00:00
2023-07-05 20:33:21 +00:00
federationDomainSameIssuerAddress2 . Status . Phase = configv1alpha1 . FederationDomainPhaseError
federationDomainSameIssuerAddress2 . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
happyIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
happyIssuerURLValidCondition ( frozenMetav1Now , 123 ) ,
sadOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-23 23:25:44 +00:00
2023-07-05 20:33:21 +00:00
federationDomainWithInvalidIssuerURL . Status . Phase = configv1alpha1 . FederationDomainPhaseError
federationDomainWithInvalidIssuerURL . Status . Conditions = [ ] configv1alpha1 . Condition {
2023-06-30 20:43:40 +00:00
unknownIssuerIsUniqueCondition ( frozenMetav1Now , 123 ) ,
sadIssuerURLValidConditionCannotParse ( frozenMetav1Now , 123 ) ,
unknownOneTLSSecretPerIssuerHostnameCondition ( frozenMetav1Now , 123 ) ,
sadReadyCondition ( frozenMetav1Now , 123 ) ,
}
2020-10-23 23:25:44 +00:00
expectedActions := [ ] coretesting . Action {
2023-06-30 20:43:40 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2023-06-30 20:43:40 +00:00
"status" ,
federationDomainDifferentIssuerAddress . Namespace ,
federationDomainDifferentIssuerAddress ,
2020-10-23 23:25:44 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomainSameIssuerAddress1 . Namespace ,
federationDomainSameIssuerAddress1 ,
2020-10-23 23:25:44 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomainSameIssuerAddress2 . Namespace ,
federationDomainSameIssuerAddress2 ,
2020-10-23 23:25:44 +00:00
) ,
2021-02-11 02:46:03 +00:00
coretesting . NewUpdateSubresourceAction (
2020-12-16 22:27:09 +00:00
federationDomainGVR ,
2021-02-11 02:46:03 +00:00
"status" ,
2020-12-16 22:27:09 +00:00
federationDomainWithInvalidIssuerURL . Namespace ,
federationDomainWithInvalidIssuerURL ,
2020-10-23 23:25:44 +00:00
) ,
}
r . ElementsMatch ( expectedActions , pinnipedAPIClient . Actions ( ) )
} )
} )
2020-12-16 22:27:09 +00:00
when ( "there are no FederationDomains in the informer" , func ( ) {
2020-10-09 00:40:58 +00:00
it ( "keeps waiting for one" , func ( ) {
startInformersAndController ( )
err := controllerlib . TestSync ( t , subject , * syncContext )
r . NoError ( err )
r . Empty ( pinnipedAPIClient . Actions ( ) )
2023-06-13 21:20:39 +00:00
r . True ( federationDomainsSetter . SetFederationDomainsWasCalled )
r . Empty ( federationDomainsSetter . FederationDomainsReceived )
2020-10-09 00:40:58 +00:00
} )
} )
} , spec . Parallel ( ) , spec . Report ( report . Terminal { } ) )
}