|
| 1 | +package credname |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/1Password/shell-plugins/sdk" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestGettingCredentialIDsFromNames(t *testing.T) { |
| 11 | + names := []sdk.CredentialName{ |
| 12 | + APIClientCredentials, |
| 13 | + APIKey, |
| 14 | + APIToken, |
| 15 | + AccessKey, |
| 16 | + AccessToken, |
| 17 | + AppPassword, |
| 18 | + AppToken, |
| 19 | + AuthToken, |
| 20 | + CLIToken, |
| 21 | + Credential, |
| 22 | + Credentials, |
| 23 | + DatabaseCredentials, |
| 24 | + LoginDetails, |
| 25 | + PersonalAPIToken, |
| 26 | + PersonalAccessToken, |
| 27 | + RegistryCredentials, |
| 28 | + SecretKey, |
| 29 | + sdk.CredentialName(""), |
| 30 | + sdk.CredentialName("Database-specific Credentials"), |
| 31 | + sdk.CredentialName("Public/Private Key-Pair"), |
| 32 | + sdk.CredentialName("Public/Private Key Pair"), |
| 33 | + sdk.CredentialName("KeyPair"), |
| 34 | + sdk.CredentialName("___some-test/name "), |
| 35 | + sdk.CredentialName("this -is/NOT-a, real. _- / life---- scENARIo..."), |
| 36 | + sdk.CredentialName("___some,.other test/name-which -is/NOT-a, real. , - ./ - life_scENARIo..."), |
| 37 | + } |
| 38 | + |
| 39 | + expectedIDs := []string{ |
| 40 | + "api_client_credentials", |
| 41 | + "api_key", |
| 42 | + "api_token", |
| 43 | + "access_key", |
| 44 | + "access_token", |
| 45 | + "app_password", |
| 46 | + "app_token", |
| 47 | + "auth_token", |
| 48 | + "cli_token", |
| 49 | + "credential", |
| 50 | + "credentials", |
| 51 | + "database_credentials", |
| 52 | + "login_details", |
| 53 | + "personal_api_token", |
| 54 | + "personal_access_token", |
| 55 | + "registry_credentials", |
| 56 | + "secret_key", |
| 57 | + "", |
| 58 | + "database_specific_credentials", |
| 59 | + "public_private_key_pair", |
| 60 | + "public_private_key_pair", |
| 61 | + "keypair", |
| 62 | + "some_test_name", |
| 63 | + "this_is_not_a_real_life_scenario", |
| 64 | + "some_other_test_name_which_is_not_a_real_life_scenario", |
| 65 | + } |
| 66 | + |
| 67 | + for i, name := range names { |
| 68 | + assert.Equal(t, expectedIDs[i], name.ID().String()) |
| 69 | + } |
| 70 | +} |
0 commit comments