forked from baron/baron-sso
headless login으로 리펙토링
This commit is contained in:
@@ -425,16 +425,16 @@ func TestRotateClientSecret_PersistsForLaterDetailFetch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
func TestUpdateClient_HeadlessLoginSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
getCount := 0
|
||||
|
||||
transport := roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
||||
if r.Method == http.MethodGet && r.URL.Path == "/clients/client-trusted" {
|
||||
if r.Method == http.MethodGet && r.URL.Path == "/clients/client-headless-login" {
|
||||
getCount++
|
||||
if getCount == 1 {
|
||||
return httpJSONAny(r, http.StatusOK, map[string]any{
|
||||
"client_id": "client-trusted",
|
||||
"client_name": "Trusted Before",
|
||||
"client_id": "client-headless-login",
|
||||
"client_name": "Headless Login Before",
|
||||
"redirect_uris": []string{"https://before.example.com/callback"},
|
||||
"grant_types": []string{"authorization_code", "refresh_token"},
|
||||
"response_types": []string{"code"},
|
||||
@@ -447,14 +447,14 @@ func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
}
|
||||
|
||||
return httpJSONAny(r, http.StatusOK, map[string]any{
|
||||
"client_id": "client-trusted",
|
||||
"client_name": "Trusted After",
|
||||
"redirect_uris": []string{"https://trusted.example.com/callback"},
|
||||
"client_id": "client-headless-login",
|
||||
"client_name": "Headless Login After",
|
||||
"redirect_uris": []string{"https://headless.example.com/callback"},
|
||||
"grant_types": []string{"authorization_code", "refresh_token"},
|
||||
"response_types": []string{"code"},
|
||||
"scope": "openid profile",
|
||||
"token_endpoint_auth_method": "private_key_jwt",
|
||||
"jwks_uri": "https://trusted.example.com/jwks.json",
|
||||
"jwks_uri": "https://headless.example.com/jwks.json",
|
||||
"metadata": map[string]any{
|
||||
"status": "active",
|
||||
"headless_login_enabled": true,
|
||||
@@ -463,17 +463,17 @@ func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
}), nil
|
||||
}
|
||||
|
||||
if r.Method == http.MethodPut && r.URL.Path == "/clients/client-trusted" {
|
||||
if r.Method == http.MethodPut && r.URL.Path == "/clients/client-headless-login" {
|
||||
return httpJSONAny(r, http.StatusOK, map[string]any{
|
||||
"client_id": "client-trusted",
|
||||
"client_name": "Trusted After",
|
||||
"client_secret": "trusted-secret",
|
||||
"redirect_uris": []string{"https://trusted.example.com/callback"},
|
||||
"client_id": "client-headless-login",
|
||||
"client_name": "Headless Login After",
|
||||
"client_secret": "headless-secret",
|
||||
"redirect_uris": []string{"https://headless.example.com/callback"},
|
||||
"grant_types": []string{"authorization_code", "refresh_token"},
|
||||
"response_types": []string{"code"},
|
||||
"scope": "openid profile",
|
||||
"token_endpoint_auth_method": "private_key_jwt",
|
||||
"jwks_uri": "https://trusted.example.com/jwks.json",
|
||||
"jwks_uri": "https://headless.example.com/jwks.json",
|
||||
"metadata": map[string]any{
|
||||
"status": "active",
|
||||
"headless_login_enabled": true,
|
||||
@@ -507,16 +507,16 @@ func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
app.Get("/api/v1/dev/clients/:id", h.GetClient)
|
||||
|
||||
updateBody, _ := json.Marshal(map[string]any{
|
||||
"name": "Trusted After",
|
||||
"redirectUris": []string{"https://trusted.example.com/callback"},
|
||||
"name": "Headless Login After",
|
||||
"redirectUris": []string{"https://headless.example.com/callback"},
|
||||
"tokenEndpointAuthMethod": "private_key_jwt",
|
||||
"jwksUri": "https://trusted.example.com/jwks.json",
|
||||
"jwksUri": "https://headless.example.com/jwks.json",
|
||||
"metadata": map[string]any{
|
||||
"headless_login_enabled": true,
|
||||
"request_object_signing_alg": "RS256",
|
||||
},
|
||||
})
|
||||
updateReq := httptest.NewRequest(http.MethodPut, "/api/v1/dev/clients/client-trusted", bytes.NewReader(updateBody))
|
||||
updateReq := httptest.NewRequest(http.MethodPut, "/api/v1/dev/clients/client-headless-login", bytes.NewReader(updateBody))
|
||||
updateReq.Header.Set("Content-Type", "application/json")
|
||||
|
||||
updateResp, err := app.Test(updateReq, -1)
|
||||
@@ -527,20 +527,20 @@ func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
t.Fatalf("expected update 200, got %d", updateResp.StatusCode)
|
||||
}
|
||||
|
||||
storedSecret, _ := secretRepo.GetByID(context.Background(), "client-trusted")
|
||||
if storedSecret != "trusted-secret" {
|
||||
t.Fatalf("expected postgres secret trusted-secret, got %q", storedSecret)
|
||||
storedSecret, _ := secretRepo.GetByID(context.Background(), "client-headless-login")
|
||||
if storedSecret != "headless-secret" {
|
||||
t.Fatalf("expected postgres secret headless-secret, got %q", storedSecret)
|
||||
}
|
||||
|
||||
redisSecret, err := redisRepo.Get("client_secret:client-trusted")
|
||||
redisSecret, err := redisRepo.Get("client_secret:client-headless-login")
|
||||
if err != nil {
|
||||
t.Fatalf("expected redis secret, got error: %v", err)
|
||||
}
|
||||
if redisSecret != "trusted-secret" {
|
||||
t.Fatalf("expected redis secret trusted-secret, got %q", redisSecret)
|
||||
if redisSecret != "headless-secret" {
|
||||
t.Fatalf("expected redis secret headless-secret, got %q", redisSecret)
|
||||
}
|
||||
|
||||
getReq := httptest.NewRequest(http.MethodGet, "/api/v1/dev/clients/client-trusted", nil)
|
||||
getReq := httptest.NewRequest(http.MethodGet, "/api/v1/dev/clients/client-headless-login", nil)
|
||||
getResp, err := app.Test(getReq, -1)
|
||||
if err != nil {
|
||||
t.Fatalf("get request failed: %v", err)
|
||||
@@ -557,7 +557,7 @@ func TestUpdateClient_TrustedRPSecretPersistsForLaterDetailFetch(t *testing.T) {
|
||||
if err := json.NewDecoder(getResp.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if payload.Client.ClientSecret != "trusted-secret" {
|
||||
t.Fatalf("expected detail secret trusted-secret, got %q", payload.Client.ClientSecret)
|
||||
if payload.Client.ClientSecret != "headless-secret" {
|
||||
t.Fatalf("expected detail secret headless-secret, got %q", payload.Client.ClientSecret)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user