mirror of https://github.com/docker/docs.git
Fixing unique key_id entry enforcement
Signed-off-by: Diogo Monica <diogo@docker.com>
This commit is contained in:
parent
e568babc0a
commit
c7e421a501
|
@ -23,11 +23,11 @@ type KeyDBStore struct {
|
||||||
// GormPrivateKey represents a PrivateKey in the database
|
// GormPrivateKey represents a PrivateKey in the database
|
||||||
type GormPrivateKey struct {
|
type GormPrivateKey struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
KeyID string `gorm:"not null;unique_index"`
|
KeyID string `sql:"not null;unique"`
|
||||||
Encryption string `gorm:"type:varchar(50);not null"`
|
Encryption string `sql:"not null"`
|
||||||
Algorithm string `gorm:"not null"`
|
Algorithm string `sql:"not null"`
|
||||||
Public []byte `gorm:"not null"`
|
Public []byte `sql:"not null"`
|
||||||
Private string `gorm:"not null"`
|
Private string `sql:"not null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName sets a specific table name for our GormPrivateKey
|
// TableName sets a specific table name for our GormPrivateKey
|
||||||
|
|
|
@ -79,6 +79,10 @@ func TestDoubleCreate(t *testing.T) {
|
||||||
err = dbStore.AddKey("", "", testKey)
|
err = dbStore.AddKey("", "", testKey)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// Test writing the same key in the database. Should fail.
|
||||||
|
err = dbStore.AddKey("", "", testKey)
|
||||||
|
assert.Error(t, err, "failed to add private key to database:")
|
||||||
|
|
||||||
// Test writing new key succeeds
|
// Test writing new key succeeds
|
||||||
err = dbStore.AddKey("", "", anotherTestKey)
|
err = dbStore.AddKey("", "", anotherTestKey)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue