(t *testing.T)
| 312 | } |
| 313 | |
| 314 | func TestUseKeyringUnsupportedOS(t *testing.T) { |
| 315 | // Verify that on unsupported operating systems, file-based storage is used |
| 316 | // automatically even when --use-keyring is set to true (the default). |
| 317 | t.Parallel() |
| 318 | |
| 319 | // Only run this on an unsupported OS. |
| 320 | if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { |
| 321 | t.Skipf("Skipping unsupported OS test on %s where keyring is supported", runtime.GOOS) |
| 322 | } |
| 323 | |
| 324 | t.Run("LoginWithDefaultKeyring", func(t *testing.T) { |
| 325 | t.Parallel() |
| 326 | |
| 327 | client := coderdtest.New(t, nil) |
| 328 | coderdtest.CreateFirstUser(t, client) |
| 329 | pty := ptytest.New(t) |
| 330 | |
| 331 | env := setupKeyringTestEnv(t, client.URL.String(), |
| 332 | "login", |
| 333 | "--force-tty", |
| 334 | "--no-open", |
| 335 | client.URL.String(), |
| 336 | ) |
| 337 | inv := env.inv |
| 338 | inv.Stdin = pty.Input() |
| 339 | inv.Stdout = pty.Output() |
| 340 | |
| 341 | doneChan := make(chan struct{}) |
| 342 | go func() { |
| 343 | defer close(doneChan) |
| 344 | err := inv.Run() |
| 345 | assert.NoError(t, err) |
| 346 | }() |
| 347 | |
| 348 | pty.ExpectMatch("Paste your token here:") |
| 349 | pty.WriteLine(client.SessionToken()) |
| 350 | pty.ExpectMatch("Welcome to Coder") |
| 351 | <-doneChan |
| 352 | |
| 353 | // Verify that session file WAS created (automatic fallback to file storage) |
| 354 | sessionFile := path.Join(string(env.cfg), "session") |
| 355 | _, err := os.Stat(sessionFile) |
| 356 | require.NoError(t, err, "session file should exist due to automatic fallback to file storage") |
| 357 | |
| 358 | content, err := os.ReadFile(sessionFile) |
| 359 | require.NoError(t, err, "should be able to read session file") |
| 360 | require.Equal(t, client.SessionToken(), string(content), "file should contain the session token") |
| 361 | }) |
| 362 | |
| 363 | t.Run("LogoutWithDefaultKeyring", func(t *testing.T) { |
| 364 | t.Parallel() |
| 365 | |
| 366 | client := coderdtest.New(t, nil) |
| 367 | coderdtest.CreateFirstUser(t, client) |
| 368 | pty := ptytest.New(t) |
| 369 | |
| 370 | // First login to create a session (will use file storage due to automatic fallback) |
| 371 | env := setupKeyringTestEnv(t, client.URL.String(), |
nothing calls this directly
no test coverage detected