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

Function TestInitDbxUsesAuthFileEnv

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

Source from the content-addressed store, hash-verified

570}
571
572func TestInitDbxUsesAuthFileEnv(t *testing.T) {
573 origConfig := config
574 defer func() { config = origConfig }()
575 stubUsersClient(t, &mockUsersClient{
576 getCurrentAccountFn: func() (*users.FullAccount, error) {
577 return testRootFullAccount(common.NewTeamRootInfo("team-root", "home-ns", "/Member")), nil
578 },
579 })
580
581 authFile := filepath.Join(t.TempDir(), "custom-auth.json")
582 if err := os.WriteFile(authFile, []byte(`{"api.example.com":{"personal":"file-token"}}`), 0600); err != nil {
583 t.Fatal(err)
584 }
585
586 t.Setenv(envAccessToken, "")
587 t.Setenv(envAuthFile, authFile)
588
589 cmd := newAuthTestCommand()
590 if err := cmd.Flags().Set("domain", "api.example.com"); err != nil {
591 t.Fatal(err)
592 }
593
594 if err := initDbx(cmd, nil); err != nil {
595 t.Fatal(err)
596 }
597
598 if config.Token != "file-token" {
599 t.Fatalf("expected token from %s, got %q", envAuthFile, config.Token)
600 }
601 if config.Domain != "api.example.com" {
602 t.Fatalf("expected domain from flag, got %q", config.Domain)
603 }
604 if config.PathRoot != `{".tag": "root", "root": "team-root"}` {
605 t.Fatalf("expected path root from saved token account, got %q", config.PathRoot)
606 }
607 assertCurrentAuthContext(t, authSourceSaved, false, authFileCustom)
608}
609
610func TestInitDbxRecordsSavedRefreshableAuthContext(t *testing.T) {
611 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