MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestInitDbxAccessTokenEnvTakesPrecedenceOverAuthFile

Function TestInitDbxAccessTokenEnvTakesPrecedenceOverAuthFile

cmd/root_test.go:495–524  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

493}
494
495func TestInitDbxAccessTokenEnvTakesPrecedenceOverAuthFile(t *testing.T) {
496 origConfig := config
497 defer func() { config = origConfig }()
498 stubUsersClient(t, &mockUsersClient{
499 getCurrentAccountFn: func() (*users.FullAccount, error) {
500 return testRootFullAccount(common.NewUserRootInfo("env-root", "env-home")), nil
501 },
502 })
503
504 authFile := filepath.Join(t.TempDir(), "auth.json")
505 if err := os.WriteFile(authFile, []byte(`{"":{"personal":"file-token"}}`), 0600); err != nil {
506 t.Fatal(err)
507 }
508
509 t.Setenv(envAccessToken, "env-token")
510 t.Setenv(envAuthFile, authFile)
511
512 cmd := newAuthTestCommand()
513 if err := initDbx(cmd, nil); err != nil {
514 t.Fatal(err)
515 }
516
517 if config.Token != "env-token" {
518 t.Fatalf("expected %s to take precedence, got %q", envAccessToken, config.Token)
519 }
520 if config.PathRoot != `{".tag": "root", "root": "env-root"}` {
521 t.Fatalf("expected path root from env token account, got %q", config.PathRoot)
522 }
523 assertCurrentAuthContext(t, authSourceEnv, false, authFileNone)
524}
525
526func TestInitDbxAccessTokenEnvBypassesRefresh(t *testing.T) {
527 origConfig := config

Callers

nothing calls this directly

Calls 5

stubUsersClientFunction · 0.85
testRootFullAccountFunction · 0.85
newAuthTestCommandFunction · 0.85
initDbxFunction · 0.85
assertCurrentAuthContextFunction · 0.85

Tested by

no test coverage detected