| 1 | // Copyright The gittuf Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package v02scip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/ |
| 5 | |
| 6 | import ( |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.26.0 testing/" |
| 9 | |
| 10 | "github.com/gittuf/gittuf/internal/signerverifier/sshscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/" |
| 11 | "github.com/secure-systems-lab/go-securesystemslib/signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/" |
| 12 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/" |
| 13 | ) |
| 14 | |
| 15 | func TestPersonscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/TestPerson().(t *testingscip-go gomod github.com/golang/go/src go1.26.0 testing/.Tscip-go gomod github.com/golang/go/src go1.26.0 testing/T#) { |
| 16 | keyR := sshscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/.NewKeyFromBytesscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/NewKeyFromBytes().(t, rootPubKeyBytesscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/rootPubKeyBytes.) |
| 17 | key := NewKeyFromSSLibKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/NewKeyFromSSLibKey().(keyR) |
| 18 | |
| 19 | tests := map[string]struct { |
| 20 | person *Personscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person# |
| 21 | expectedID string |
| 22 | expectedKeys []*signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/.SSLibKeyscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey# |
| 23 | expectedCustomMetadata map[string]string |
| 24 | }{ |
| 25 | "no custom metadata": { |
| 26 | person: &Personscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#{ |
| 27 | PersonIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PersonID.: "jane.doe", |
| 28 | PublicKeysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PublicKeys.: map[string]*Keyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Key#{ |
| 29 | key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.: key, |
| 30 | }, |
| 31 | }, |
| 32 | expectedID: "jane.doe", |
| 33 | expectedKeys: []*signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/.SSLibKeyscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#{keyR}, |
| 34 | expectedCustomMetadata: nil, |
| 35 | }, |
| 36 | "only associated identities": { |
| 37 | person: &Personscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#{ |
| 38 | PersonIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PersonID.: "jane.doe", |
| 39 | PublicKeysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PublicKeys.: map[string]*Keyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Key#{ |
| 40 | key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.: key, |
| 41 | }, |
| 42 | AssociatedIdentitiesscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#AssociatedIdentities.: map[string]string{ |
| 43 | "https://github.com": "jane.doe", |
| 44 | "https://gitlab.com": "jane.doe", |
| 45 | }, |
| 46 | }, |
| 47 | expectedID: "jane.doe", |
| 48 | expectedKeys: []*signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/.SSLibKeyscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#{keyR}, |
| 49 | expectedCustomMetadata: map[string]string{ |
| 50 | fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("%s https://github.com", associatedIdentityKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/associatedIdentityKey.): "jane.doe", |
| 51 | fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("%s https://gitlab.com", associatedIdentityKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/associatedIdentityKey.): "jane.doe", |
| 52 | }, |
| 53 | }, |
| 54 | "only custom metadata": { |
| 55 | person: &Personscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#{ |
| 56 | PersonIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PersonID.: "jane.doe", |
| 57 | PublicKeysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PublicKeys.: map[string]*Keyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Key#{ |
| 58 | key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.: key, |
| 59 | }, |
| 60 | Customscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#Custom.: map[string]string{ |
| 61 | "key": "value", |
| 62 | }, |
| 63 | }, |
| 64 | expectedID: "jane.doe", |
| 65 | expectedKeys: []*signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/.SSLibKeyscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#{keyR}, |
| 66 | expectedCustomMetadata: map[string]string{ |
| 67 | "key": "value", |
| 68 | }, |
| 69 | }, |
| 70 | "both associated identities and custom metadata": { |
| 71 | person: &Personscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#{ |
| 72 | PersonIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PersonID.: "jane.doe", |
| 73 | PublicKeysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#PublicKeys.: map[string]*Keyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Key#{ |
| 74 | key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.: key, |
| 75 | }, |
| 76 | AssociatedIdentitiesscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#AssociatedIdentities.: map[string]string{ |
| 77 | "https://github.com": "jane.doe", |
| 78 | "https://gitlab.com": "jane.doe", |
| 79 | }, |
| 80 | Customscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#Custom.: map[string]string{ |
| 81 | "key": "value", |
| 82 | }, |
| 83 | }, |
| 84 | expectedID: "jane.doe", |
| 85 | expectedKeys: []*signerverifierscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/.SSLibKeyscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#{keyR}, |
| 86 | expectedCustomMetadata: map[string]string{ |
| 87 | fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("%s https://github.com", associatedIdentityKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/associatedIdentityKey.): "jane.doe", |
| 88 | fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("%s https://gitlab.com", associatedIdentityKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/associatedIdentityKey.): "jane.doe", |
| 89 | "key": "value", |
| 90 | }, |
| 91 | }, |
| 92 | } |
| 93 | |
| 94 | for name, test := range tests { |
| 95 | id := test.person.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#ID().() |
| 96 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedID, id, fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("unexpected person ID in test '%s'", name)) |
| 97 | |
| 98 | keys := test.person.Keysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#Keys().() |
| 99 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedKeys, keys, fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("unexpected keys in test '%s'", name)) |
| 100 | |
| 101 | customMetadata := test.person.CustomMetadatascip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf/v02`/Person#CustomMetadata().() |
| 102 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedCustomMetadata, customMetadata, fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("unexpected custom metadata in test '%s'", name)) |
| 103 | } |
| 104 | } |