|
|
@@ -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
|
|
|
@@ -222,12 +224,14 @@ func TestDB_GetAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
dbacc := &dbAccount{
|
|
|
- ID: accID,
|
|
|
- Status: acme.StatusDeactivated,
|
|
|
- CreatedAt: now,
|
|
|
- DeactivatedAt: now,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ ID: accID,
|
|
|
+ Status: acme.StatusDeactivated,
|
|
|
+ CreatedAt: now,
|
|
|
+ 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
|
|
|
@@ -390,9 +397,10 @@ func TestDB_CreateAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
acc := &acme.Account{
|
|
|
- Status: acme.StatusValid,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ Status: acme.StatusValid,
|
|
|
+ Contact: []string{"foo", "bar"},
|
|
|
+ Key: jwk,
|
|
|
+ LocationPrefix: locationPrefix,
|
|
|
}
|
|
|
return test{
|
|
|
db: &db.MockNoSQLDB{
|
|
|
@@ -413,9 +421,10 @@ func TestDB_CreateAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
acc := &acme.Account{
|
|
|
- Status: acme.StatusValid,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ Status: acme.StatusValid,
|
|
|
+ Contact: []string{"foo", "bar"},
|
|
|
+ Key: jwk,
|
|
|
+ LocationPrefix: locationPrefix,
|
|
|
}
|
|
|
return test{
|
|
|
db: &db.MockNoSQLDB{
|
|
|
@@ -436,9 +445,10 @@ func TestDB_CreateAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
acc := &acme.Account{
|
|
|
- Status: acme.StatusValid,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ 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))
|
|
|
@@ -479,9 +491,10 @@ func TestDB_CreateAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
acc := &acme.Account{
|
|
|
- Status: acme.StatusValid,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ 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))
|
|
|
@@ -539,12 +554,14 @@ func TestDB_UpdateAccount(t *testing.T) {
|
|
|
jwk, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
assert.FatalError(t, err)
|
|
|
dbacc := &dbAccount{
|
|
|
- ID: accID,
|
|
|
- Status: acme.StatusDeactivated,
|
|
|
- CreatedAt: now,
|
|
|
- DeactivatedAt: now,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ ID: accID,
|
|
|
+ Status: acme.StatusDeactivated,
|
|
|
+ CreatedAt: now,
|
|
|
+ DeactivatedAt: now,
|
|
|
+ Contact: []string{"foo", "bar"},
|
|
|
+ LocationPrefix: "foo",
|
|
|
+ ProvisionerName: "alpha",
|
|
|
+ Key: jwk,
|
|
|
}
|
|
|
b, err := json.Marshal(dbacc)
|
|
|
assert.FatalError(t, err)
|
|
|
@@ -644,10 +661,12 @@ func TestDB_UpdateAccount(t *testing.T) {
|
|
|
},
|
|
|
"ok": func(t *testing.T) test {
|
|
|
acc := &acme.Account{
|
|
|
- ID: accID,
|
|
|
- Status: acme.StatusDeactivated,
|
|
|
- Contact: []string{"foo", "bar"},
|
|
|
- Key: jwk,
|
|
|
+ ID: accID,
|
|
|
+ Status: acme.StatusDeactivated,
|
|
|
+ Contact: []string{"baz", "zap"},
|
|
|
+ LocationPrefix: "bar",
|
|
|
+ ProvisionerName: "beta",
|
|
|
+ Key: jwk,
|
|
|
}
|
|
|
return test{
|
|
|
acc: acc,
|
|
|
@@ -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)
|
|
|
}
|
|
|
})
|
|
|
}
|