fix(import): add import for app and machine keys (#4536)

* fix(import): add import for app and machine keys

* fix(export): add review changes

* fix(import): Apply suggestions from code review

Co-authored-by: Livio Spring <livio.a@gmail.com>

* fix(import): add review changes

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Stefan Benz
2022-10-18 16:07:30 +01:00
committed by GitHub
parent 3270a94291
commit 556f381a5a
18 changed files with 648 additions and 131 deletions

View File

@@ -182,6 +182,189 @@ func Test_AuthNKeyPrepares(t *testing.T) {
},
object: nil,
},
{
name: "prepareAuthNKeysDataQuery no result",
prepare: prepareAuthNKeysDataQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
` projections.authn_keys.creation_date,`+
` projections.authn_keys.resource_owner,`+
` projections.authn_keys.sequence,`+
` projections.authn_keys.expiration,`+
` projections.authn_keys.type,`+
` projections.authn_keys.identifier,`+
` projections.authn_keys.public_key,`+
` COUNT(*) OVER ()`+
` FROM projections.authn_keys`),
nil,
nil,
),
},
object: &AuthNKeysData{AuthNKeysData: []*AuthNKeyData{}},
},
{
name: "prepareAuthNKeysDataQuery one result",
prepare: prepareAuthNKeysDataQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
` projections.authn_keys.creation_date,`+
` projections.authn_keys.resource_owner,`+
` projections.authn_keys.sequence,`+
` projections.authn_keys.expiration,`+
` projections.authn_keys.type,`+
` projections.authn_keys.identifier,`+
` projections.authn_keys.public_key,`+
` COUNT(*) OVER ()`+
` FROM projections.authn_keys`),
[]string{
"id",
"creation_date",
"resource_owner",
"sequence",
"expiration",
"type",
"identifier",
"public_key",
"count",
},
[][]driver.Value{
{
"id",
testNow,
"ro",
uint64(20211109),
testNow,
1,
"identifier",
[]byte("public"),
},
},
),
},
object: &AuthNKeysData{
SearchResponse: SearchResponse{
Count: 1,
},
AuthNKeysData: []*AuthNKeyData{
{
ID: "id",
CreationDate: testNow,
ResourceOwner: "ro",
Sequence: 20211109,
Expiration: testNow,
Type: domain.AuthNKeyTypeJSON,
Identifier: "identifier",
PublicKey: []byte("public"),
},
},
},
},
{
name: "prepareAuthNKeysDataQuery multiple result",
prepare: prepareAuthNKeysDataQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
` projections.authn_keys.creation_date,`+
` projections.authn_keys.resource_owner,`+
` projections.authn_keys.sequence,`+
` projections.authn_keys.expiration,`+
` projections.authn_keys.type,`+
` projections.authn_keys.identifier,`+
` projections.authn_keys.public_key,`+
` COUNT(*) OVER ()`+
` FROM projections.authn_keys`),
[]string{
"id",
"creation_date",
"resource_owner",
"sequence",
"expiration",
"type",
"identifier",
"public_key",
"count",
},
[][]driver.Value{
{
"id-1",
testNow,
"ro",
uint64(20211109),
testNow,
1,
"identifier1",
[]byte("public1"),
},
{
"id-2",
testNow,
"ro",
uint64(20211109),
testNow,
1,
"identifier2",
[]byte("public2"),
},
},
),
},
object: &AuthNKeysData{
SearchResponse: SearchResponse{
Count: 2,
},
AuthNKeysData: []*AuthNKeyData{
{
ID: "id-1",
CreationDate: testNow,
ResourceOwner: "ro",
Sequence: 20211109,
Expiration: testNow,
Type: domain.AuthNKeyTypeJSON,
Identifier: "identifier1",
PublicKey: []byte("public1"),
},
{
ID: "id-2",
CreationDate: testNow,
ResourceOwner: "ro",
Sequence: 20211109,
Expiration: testNow,
Type: domain.AuthNKeyTypeJSON,
Identifier: "identifier2",
PublicKey: []byte("public2"),
},
},
},
},
{
name: "prepareAuthNKeysDataQuery sql err",
prepare: prepareAuthNKeysDataQuery,
want: want{
sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
` projections.authn_keys.creation_date,`+
` projections.authn_keys.resource_owner,`+
` projections.authn_keys.sequence,`+
` projections.authn_keys.expiration,`+
` projections.authn_keys.type,`+
` projections.authn_keys.identifier,`+
` projections.authn_keys.public_key,`+
` COUNT(*) OVER ()`+
` FROM projections.authn_keys`),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {
if !errors.Is(err, sql.ErrConnDone) {
return fmt.Errorf("err should be sql.ErrConnDone got: %w", err), false
}
return nil, true
},
},
object: nil,
},
{
name: "prepareAuthNKeyQuery no result",
prepare: prepareAuthNKeyQuery,