Improving unit test coverage of pkg/issuer/acme/setup.go
Signed-off-by: Sathyanarayanan Saravanamuthu <sathya.chozhanaadan@gmail.com>
This commit is contained in:
parent
4de4bb510c
commit
401fb2dc34
@ -122,6 +122,9 @@ func TestAcme_Setup(t *testing.T) {
|
||||
// Error returned by cl.GetReg
|
||||
getRegErr error
|
||||
|
||||
// Error return by cl.UpdateRegistration
|
||||
updateRegError error
|
||||
|
||||
// Error returned when creating ACME account key.
|
||||
acmePrivKeySecretCreateErr error
|
||||
// ACME account key created by createAccountPrivateKey.
|
||||
@ -382,6 +385,127 @@ func TestAcme_Setup(t *testing.T) {
|
||||
gen.SetIssuerConditionMessage(messageAccountRegistered)),
|
||||
},
|
||||
},
|
||||
"ACME account with legacy EAB key algorithm set, spec email different from registered email and registered successfully": {
|
||||
issuer: gen.IssuerFrom(baseIssuer,
|
||||
gen.SetIssuerACMEEmail(someEmail),
|
||||
gen.SetIssuerACMEEABWithKeyAlgorithm(someString, someString, cmacme.HS256)),
|
||||
kfsKey: rsaPrivKey,
|
||||
removeClientShouldBeCalled: true,
|
||||
addClientShouldBeCalled: true,
|
||||
eabSecret: eabSecret,
|
||||
registerErr: acmeapi.ErrAccountAlreadyExists,
|
||||
getRegAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{"some@test.com"},
|
||||
},
|
||||
expectedRegisteredAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{someEmailURL},
|
||||
},
|
||||
expectedConditions: []cmapi.IssuerCondition{
|
||||
*gen.IssuerConditionFrom(readyTrueCondition,
|
||||
gen.SetIssuerConditionStatus(cmmeta.ConditionTrue),
|
||||
gen.SetIssuerConditionReason(successAccountRegistered),
|
||||
gen.SetIssuerConditionMessage(messageAccountRegistered)),
|
||||
},
|
||||
},
|
||||
"ACME account with legacy EAB key algorithm set, spec email different from registered email and registered failed": {
|
||||
issuer: gen.IssuerFrom(baseIssuer,
|
||||
gen.SetIssuerACMEEmail(someEmail),
|
||||
gen.SetIssuerACMEEABWithKeyAlgorithm(someString, someString, cmacme.HS256)),
|
||||
kfsKey: rsaPrivKey,
|
||||
removeClientShouldBeCalled: true,
|
||||
eabSecret: eabSecret,
|
||||
registerErr: acmeapi.ErrAccountAlreadyExists,
|
||||
getRegAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{"some@test.com"},
|
||||
},
|
||||
expectedRegisteredAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{someEmailURL},
|
||||
},
|
||||
updateRegError: someErr,
|
||||
wantsErr: true,
|
||||
expectedConditions: []cmapi.IssuerCondition{
|
||||
*gen.IssuerConditionFrom(readyTrueCondition,
|
||||
gen.SetIssuerConditionStatus(cmmeta.ConditionFalse),
|
||||
gen.SetIssuerConditionReason(errorAccountUpdateFailed),
|
||||
gen.SetIssuerConditionMessage(fmt.Sprintf("%s%s", messageAccountUpdateFailed, someString))),
|
||||
},
|
||||
expectedEvents: []string{
|
||||
fmt.Sprintf("%s %s %s", corev1.EventTypeWarning, errorAccountUpdateFailed, fmt.Sprintf("%s%s", messageAccountUpdateFailed, someString))},
|
||||
},
|
||||
"ACME account with legacy EAB key algorithm set, spec email different from registered email and registered failed with non-retryable ACME Error": {
|
||||
issuer: gen.IssuerFrom(baseIssuer,
|
||||
gen.SetIssuerACMEEmail(someEmail),
|
||||
gen.SetIssuerACMEEABWithKeyAlgorithm(someString, someString, cmacme.HS256)),
|
||||
kfsKey: rsaPrivKey,
|
||||
removeClientShouldBeCalled: true,
|
||||
eabSecret: eabSecret,
|
||||
registerErr: acmeapi.ErrAccountAlreadyExists,
|
||||
getRegAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{"some@test.com"},
|
||||
},
|
||||
expectedRegisteredAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{someEmailURL},
|
||||
},
|
||||
updateRegError: acmeErr450,
|
||||
wantsErr: false,
|
||||
expectedConditions: []cmapi.IssuerCondition{
|
||||
*gen.IssuerConditionFrom(readyTrueCondition,
|
||||
gen.SetIssuerConditionStatus(cmmeta.ConditionFalse),
|
||||
gen.SetIssuerConditionReason(errorAccountUpdateFailed),
|
||||
gen.SetIssuerConditionMessage(fmt.Sprintf("%s%s", messageAccountUpdateFailed, acmeErr450.Error()))),
|
||||
},
|
||||
expectedEvents: []string{
|
||||
fmt.Sprintf("%s %s %s", corev1.EventTypeWarning, errorAccountUpdateFailed, fmt.Sprintf("%s%s", messageAccountUpdateFailed, acmeErr450.Error()))},
|
||||
},
|
||||
"ACME account with legacy EAB key algorithm set, spec email different from registered email and registered failed with retryable ACME Error": {
|
||||
issuer: gen.IssuerFrom(baseIssuer,
|
||||
gen.SetIssuerACMEEmail(someEmail),
|
||||
gen.SetIssuerACMEEABWithKeyAlgorithm(someString, someString, cmacme.HS256)),
|
||||
kfsKey: rsaPrivKey,
|
||||
removeClientShouldBeCalled: true,
|
||||
eabSecret: eabSecret,
|
||||
registerErr: acmeapi.ErrAccountAlreadyExists,
|
||||
getRegAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{"some@test.com"},
|
||||
},
|
||||
expectedRegisteredAcc: &acmeapi.Account{ExternalAccountBinding: &acmeapi.ExternalAccountBinding{
|
||||
KID: someString,
|
||||
Key: []byte(eabKey),
|
||||
},
|
||||
Contact: []string{someEmailURL},
|
||||
},
|
||||
updateRegError: acmeErr500,
|
||||
wantsErr: true,
|
||||
expectedConditions: []cmapi.IssuerCondition{
|
||||
*gen.IssuerConditionFrom(readyTrueCondition,
|
||||
gen.SetIssuerConditionStatus(cmmeta.ConditionFalse),
|
||||
gen.SetIssuerConditionReason(errorAccountUpdateFailed),
|
||||
gen.SetIssuerConditionMessage(fmt.Sprintf("%s%s", messageAccountUpdateFailed, acmeErr500.Error()))),
|
||||
},
|
||||
expectedEvents: []string{
|
||||
fmt.Sprintf("%s %s %s", corev1.EventTypeWarning, errorAccountUpdateFailed, fmt.Sprintf("%s%s", messageAccountUpdateFailed, acmeErr500.Error()))},
|
||||
},
|
||||
}
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@ -426,6 +550,9 @@ func TestAcme_Setup(t *testing.T) {
|
||||
FakeGetReg: func(context.Context, string) (*acmeapi.Account, error) {
|
||||
return test.getRegAcc, test.getRegErr
|
||||
},
|
||||
FakeUpdateReg: func(ctx context.Context, a *acmeapi.Account) (*acmeapi.Account, error) {
|
||||
return a, test.updateRegError
|
||||
},
|
||||
}
|
||||
|
||||
// Mock events recorder.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user