MCPcopy Create free account
hub / github.com/algolia/cli / TestGetValidToken_SelfHealsIdentityFromRefresh

Function TestGetValidToken_SelfHealsIdentityFromRefresh

pkg/auth/token_store_test.go:109–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func TestGetValidToken_SelfHealsIdentityFromRefresh(t *testing.T) {
110 keyring.MockInit()
111
112 // A session created before identity was persisted: no user fields yet.
113 require.NoError(t, persistToken(StoredToken{
114 AccessToken: "old-access",
115 RefreshToken: "refresh-1",
116 ExpiresAt: time.Now().Unix() - 60,
117 }))
118
119 client := newRefreshServer(t, dashboard.OAuthTokenResponse{
120 AccessToken: "new-access",
121 RefreshToken: "refresh-2",
122 ExpiresIn: 7200,
123 CreatedAt: time.Now().Unix(),
124 User: &dashboard.User{
125 ID: 7,
126 Email: "healed@test.com",
127 Name: "Healed User",
128 },
129 })
130
131 _, err := GetValidToken(client)
132 require.NoError(t, err)
133
134 stored := LoadToken()
135 require.NotNil(t, stored)
136 // Identity is back-filled from the refresh response.
137 assert.Equal(t, "7", stored.UserID)
138 assert.Equal(t, "healed@test.com", stored.Email)
139 assert.Equal(t, "Healed User", stored.Name)
140}

Callers

nothing calls this directly

Calls 4

persistTokenFunction · 0.85
newRefreshServerFunction · 0.85
GetValidTokenFunction · 0.85
LoadTokenFunction · 0.85

Tested by

no test coverage detected