(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func TestMigrationSecureStorage(t *testing.T) { |
| 46 | cfg := config.ReadFromString(` |
| 47 | hosts: |
| 48 | github.com: |
| 49 | user: userOne |
| 50 | git_protocol: ssh |
| 51 | enterprise.com: |
| 52 | user: userTwo |
| 53 | git_protocol: https |
| 54 | `) |
| 55 | |
| 56 | userOneToken := "userOne-token" |
| 57 | userTwoToken := "userTwo-token" |
| 58 | |
| 59 | keyring.MockInit() |
| 60 | require.NoError(t, keyring.Set("gh:github.com", "", userOneToken)) |
| 61 | require.NoError(t, keyring.Set("gh:enterprise.com", "", userTwoToken)) |
| 62 | |
| 63 | var m migration.MultiAccount |
| 64 | require.NoError(t, m.Do(cfg)) |
| 65 | |
| 66 | // Verify token gets stored with host and username |
| 67 | gotUserOneToken, err := keyring.Get("gh:github.com", "userOne") |
| 68 | require.NoError(t, err) |
| 69 | require.Equal(t, userOneToken, gotUserOneToken) |
| 70 | |
| 71 | // Verify token still exists with only host |
| 72 | gotUserOneToken, err = keyring.Get("gh:github.com", "") |
| 73 | require.NoError(t, err) |
| 74 | require.Equal(t, userOneToken, gotUserOneToken) |
| 75 | |
| 76 | // Verify token gets stored with host and username |
| 77 | gotUserTwoToken, err := keyring.Get("gh:enterprise.com", "userTwo") |
| 78 | require.NoError(t, err) |
| 79 | require.Equal(t, userTwoToken, gotUserTwoToken) |
| 80 | |
| 81 | // Verify token still exists with only host |
| 82 | gotUserTwoToken, err = keyring.Get("gh:enterprise.com", "") |
| 83 | require.NoError(t, err) |
| 84 | require.Equal(t, userTwoToken, gotUserTwoToken) |
| 85 | |
| 86 | // First we'll check that the users have been created with no config underneath them |
| 87 | requireKeyExists(t, cfg, []string{"hosts", "github.com", "users", "userOne"}) |
| 88 | requireKeyExists(t, cfg, []string{"hosts", "enterprise.com", "users", "userTwo"}) |
| 89 | |
| 90 | // Then we'll check that the old data has been left alone |
| 91 | requireKeyWithValue(t, cfg, []string{"hosts", "github.com", "user"}, "userOne") |
| 92 | requireKeyWithValue(t, cfg, []string{"hosts", "github.com", "git_protocol"}, "ssh") |
| 93 | |
| 94 | requireKeyWithValue(t, cfg, []string{"hosts", "enterprise.com", "user"}, "userTwo") |
| 95 | requireKeyWithValue(t, cfg, []string{"hosts", "enterprise.com", "git_protocol"}, "https") |
| 96 | } |
| 97 | |
| 98 | func TestPreVersionIsEmptyString(t *testing.T) { |
| 99 | var m migration.MultiAccount |
nothing calls this directly
no test coverage detected