@ -197,6 +197,8 @@ func TestDB_getAccountIDByKeyID(t *testing.T) {
func TestDB_GetAccount ( t * testing . T ) {
accID := "accID"
locationPrefix := "https://test.ca.smallstep.com/acme/foo/account/"
provisionerName := "foo"
type test struct {
db nosql . DB
err error
@ -228,6 +230,8 @@ func TestDB_GetAccount(t *testing.T) {
DeactivatedAt : now ,
Contact : [ ] string { "foo" , "bar" } ,
Key : jwk ,
LocationPrefix : locationPrefix ,
ProvisionerName : provisionerName ,
}
b , err := json . Marshal ( dbacc )
assert . FatalError ( t , err )
@ -266,6 +270,8 @@ func TestDB_GetAccount(t *testing.T) {
assert . Equals ( t , acc . ID , tc . dbacc . ID )
assert . Equals ( t , acc . Status , tc . dbacc . Status )
assert . Equals ( t , acc . Contact , tc . dbacc . Contact )
assert . Equals ( t , acc . LocationPrefix , tc . dbacc . LocationPrefix )
assert . Equals ( t , acc . ProvisionerName , tc . dbacc . ProvisionerName )
assert . Equals ( t , acc . Key . KeyID , tc . dbacc . Key . KeyID )
}
} )
@ -379,6 +385,7 @@ func TestDB_GetAccountByKeyID(t *testing.T) {
}
func TestDB_CreateAccount ( t * testing . T ) {
locationPrefix := "https://test.ca.smallstep.com/acme/foo/account/"
type test struct {
db nosql . DB
acc * acme . Account
@ -393,6 +400,7 @@ func TestDB_CreateAccount(t *testing.T) {
Status : acme . StatusValid ,
Contact : [ ] string { "foo" , "bar" } ,
Key : jwk ,
LocationPrefix : locationPrefix ,
}
return test {
db : & db . MockNoSQLDB {
@ -416,6 +424,7 @@ func TestDB_CreateAccount(t *testing.T) {
Status : acme . StatusValid ,
Contact : [ ] string { "foo" , "bar" } ,
Key : jwk ,
LocationPrefix : locationPrefix ,
}
return test {
db : & db . MockNoSQLDB {
@ -439,6 +448,7 @@ func TestDB_CreateAccount(t *testing.T) {
Status : acme . StatusValid ,
Contact : [ ] string { "foo" , "bar" } ,
Key : jwk ,
LocationPrefix : locationPrefix ,
}
return test {
db : & db . MockNoSQLDB {
@ -456,6 +466,8 @@ func TestDB_CreateAccount(t *testing.T) {
assert . FatalError ( t , json . Unmarshal ( nu , dbacc ) )
assert . Equals ( t , dbacc . ID , string ( key ) )
assert . Equals ( t , dbacc . Contact , acc . Contact )
assert . Equals ( t , dbacc . LocationPrefix , acc . LocationPrefix )
assert . Equals ( t , dbacc . ProvisionerName , acc . ProvisionerName )
assert . Equals ( t , dbacc . Key . KeyID , acc . Key . KeyID )
assert . True ( t , clock . Now ( ) . Add ( - time . Minute ) . Before ( dbacc . CreatedAt ) )
assert . True ( t , clock . Now ( ) . Add ( time . Minute ) . After ( dbacc . CreatedAt ) )
@ -482,6 +494,7 @@ func TestDB_CreateAccount(t *testing.T) {
Status : acme . StatusValid ,
Contact : [ ] string { "foo" , "bar" } ,
Key : jwk ,
LocationPrefix : locationPrefix ,
}
return test {
db : & db . MockNoSQLDB {
@ -500,6 +513,8 @@ func TestDB_CreateAccount(t *testing.T) {
assert . FatalError ( t , json . Unmarshal ( nu , dbacc ) )
assert . Equals ( t , dbacc . ID , string ( key ) )
assert . Equals ( t , dbacc . Contact , acc . Contact )
assert . Equals ( t , dbacc . LocationPrefix , acc . LocationPrefix )
assert . Equals ( t , dbacc . ProvisionerName , acc . ProvisionerName )
assert . Equals ( t , dbacc . Key . KeyID , acc . Key . KeyID )
assert . True ( t , clock . Now ( ) . Add ( - time . Minute ) . Before ( dbacc . CreatedAt ) )
assert . True ( t , clock . Now ( ) . Add ( time . Minute ) . After ( dbacc . CreatedAt ) )
@ -544,6 +559,8 @@ func TestDB_UpdateAccount(t *testing.T) {
CreatedAt : now ,
DeactivatedAt : now ,
Contact : [ ] string { "foo" , "bar" } ,
LocationPrefix : "foo" ,
ProvisionerName : "alpha" ,
Key : jwk ,
}
b , err := json . Marshal ( dbacc )
@ -646,7 +663,9 @@ func TestDB_UpdateAccount(t *testing.T) {
acc := & acme . Account {
ID : accID ,
Status : acme . StatusDeactivated ,
Contact : [ ] string { "foo" , "bar" } ,
Contact : [ ] string { "baz" , "zap" } ,
LocationPrefix : "bar" ,
ProvisionerName : "beta" ,
Key : jwk ,
}
return test {
@ -666,7 +685,10 @@ func TestDB_UpdateAccount(t *testing.T) {
assert . FatalError ( t , json . Unmarshal ( nu , dbNew ) )
assert . Equals ( t , dbNew . ID , dbacc . ID )
assert . Equals ( t , dbNew . Status , acc . Status )
assert . Equals ( t , dbNew . Contact , dbacc . Contact )
assert . Equals ( t , dbNew . Contact , acc . Contact )
// LocationPrefix should not change.
assert . Equals ( t , dbNew . LocationPrefix , dbacc . LocationPrefix )
assert . Equals ( t , dbNew . ProvisionerName , dbacc . ProvisionerName )
assert . Equals ( t , dbNew . Key . KeyID , dbacc . Key . KeyID )
assert . Equals ( t , dbNew . CreatedAt , dbacc . CreatedAt )
assert . True ( t , dbNew . DeactivatedAt . Add ( - time . Minute ) . Before ( now ) )
@ -686,12 +708,7 @@ func TestDB_UpdateAccount(t *testing.T) {
assert . HasPrefix ( t , err . Error ( ) , tc . err . Error ( ) )
}
} else {
if assert . Nil ( t , tc . err ) {
assert . Equals ( t , tc . acc . ID , dbacc . ID )
assert . Equals ( t , tc . acc . Status , dbacc . Status )
assert . Equals ( t , tc . acc . Contact , dbacc . Contact )
assert . Equals ( t , tc . acc . Key . KeyID , dbacc . Key . KeyID )
}
assert . Nil ( t , tc . err )
}
} )
}