Skip to content

Commit 10d2421

Browse files
committed
fix test
1 parent 9accbfe commit 10d2421

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

pkg/integration_testing/assume_e2e_test.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ func TestAssumeCommandE2E(t *testing.T) {
3131

3232
// Check if there's a pre-built binary to use (for CI)
3333
grantedBinary := os.Getenv("GRANTED_BINARY_PATH")
34-
34+
3535
if grantedBinary == "" {
3636
// Build the granted binary which includes assume functionality
3737
projectRoot := filepath.Join("..", "..", "..")
3838
grantedBinary = filepath.Join(t.TempDir(), "dgranted")
39-
39+
4040
// Build with the dgranted name to trigger assume CLI
4141
cmd := exec.Command("go", "build", "-o", grantedBinary, "./cmd/granted")
4242
cmd.Dir = projectRoot
@@ -76,9 +76,14 @@ region = us-east-1
7676
err := os.WriteFile(awsConfigPath, []byte(awsConfig), 0644)
7777
require.NoError(t, err)
7878

79-
// Create granted config
80-
grantedConfig := `DefaultBrowser = "stdout"
79+
// Create granted config with all necessary fields to avoid interactive prompts
80+
// Set CustomBrowserPath to "stdout" to satisfy the UserHasDefaultBrowser check
81+
grantedConfig := `DefaultBrowser = "STDOUT"
82+
CustomBrowserPath = "stdout"
8183
Ordering = "Alphabetical"
84+
[Keyring]
85+
Backend = "file"
86+
FileBackend = ""
8287
`
8388
grantedConfigPath := filepath.Join(grantedDir, "config")
8489
err = os.WriteFile(grantedConfigPath, []byte(grantedConfig), 0644)
@@ -90,16 +95,16 @@ Ordering = "Alphabetical"
9095
fmt.Sprintf("HOME=%s", homeDir),
9196
fmt.Sprintf("AWS_CONFIG_FILE=%s", awsConfigPath),
9297
fmt.Sprintf("GRANTED_STATE_DIR=%s", grantedDir),
93-
"GRANTED_QUIET=true", // Suppress output messages
94-
"FORCE_NO_ALIAS=true", // Skip alias configuration
95-
"FORCE_ASSUME_CLI=true", // Force assume mode
98+
"GRANTED_QUIET=true", // Suppress output messages
99+
"FORCE_NO_ALIAS=true", // Skip alias configuration
100+
"FORCE_ASSUME_CLI=true", // Force assume mode
96101
"PATH=" + os.Getenv("PATH"), // Preserve PATH
97102
}
98103

99104
// Run assume command with IAM profile
100105
cmd := exec.Command(grantedBinary, "test-iam")
101106
cmd.Env = env
102-
107+
103108
var stdout, stderr bytes.Buffer
104109
cmd.Stdout = &stdout
105110
cmd.Stderr = &stderr
@@ -115,17 +120,17 @@ Ordering = "Alphabetical"
115120

116121
// The assume command outputs credentials in a specific format
117122
assert.Contains(t, output, "GrantedAssume")
118-
123+
119124
// Extract credentials from output
120125
parts := strings.Fields(output)
121126
if len(parts) >= 4 {
122127
accessKey := parts[1]
123128
secretKey := parts[2]
124-
129+
125130
// For IAM profiles, we expect the actual keys to be output
126131
assert.Equal(t, "AKIAIOSFODNN7EXAMPLE", accessKey)
127132
assert.NotEqual(t, "None", secretKey)
128-
133+
129134
// Session token should be "None" for IAM profiles
130135
sessionToken := parts[3]
131136
assert.Equal(t, "None", sessionToken)
@@ -147,16 +152,16 @@ func NewAssumeE2EMockServer() *AssumeE2EMockServer {
147152
server := &AssumeE2EMockServer{
148153
accessToken: "default-test-token",
149154
}
150-
155+
151156
mux := http.NewServeMux()
152157
server.Server = &http.Server{Handler: mux}
153-
158+
154159
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
155160
server.accessCount++
156-
161+
157162
// Log the request for debugging
158163
fmt.Printf("Mock server received: %s %s %s\n", r.Method, r.URL.Path, r.Header.Get("X-Amz-Target"))
159-
164+
160165
// Handle SSO operations
161166
target := r.Header.Get("X-Amz-Target")
162167
switch target {
@@ -183,7 +188,7 @@ func NewAssumeE2EMockServer() *AssumeE2EMockServer {
183188

184189
serverURL := fmt.Sprintf("http://%s", listener.Addr().String())
185190
server.URL = serverURL
186-
191+
187192
go server.Server.Serve(listener)
188193

189194
return server
@@ -209,10 +214,10 @@ func (s *AssumeE2EMockServer) handleGetRoleCredentials(w http.ResponseWriter, r
209214
"accessKeyId": "ASIAMOCKEXAMPLE",
210215
"secretAccessKey": "mock-secret-key",
211216
"sessionToken": "mock-session-token",
212-
"expiration": time.Now().Add(1 * time.Hour).Unix() * 1000,
217+
"expiration": time.Now().Add(1*time.Hour).Unix() * 1000,
213218
},
214219
}
215-
220+
216221
w.Header().Set("Content-Type", "application/x-amz-json-1.1")
217222
json.NewEncoder(w).Encode(response)
218223
}
@@ -227,7 +232,7 @@ func (s *AssumeE2EMockServer) handleListAccounts(w http.ResponseWriter, r *http.
227232
},
228233
},
229234
}
230-
235+
231236
w.Header().Set("Content-Type", "application/x-amz-json-1.1")
232237
json.NewEncoder(w).Encode(response)
233238
}
@@ -239,7 +244,7 @@ func (s *AssumeE2EMockServer) handleCreateToken(w http.ResponseWriter, r *http.R
239244
"expiresIn": 3600,
240245
"refreshToken": "mock-refresh-token",
241246
}
242-
247+
243248
w.Header().Set("Content-Type", "application/x-amz-json-1.1")
244249
json.NewEncoder(w).Encode(response)
245-
}
250+
}

0 commit comments

Comments
 (0)