Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/app/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ func prepareAddMocks(t *testing.T, clients *shared.ClientFactory, clientsMock *s

clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
Return("api host")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This is the bulk of the changes - the version parameter was removed from the ResolveLogstashHost, which simplifies our testing mocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 praise: @mwbrooks Amazing use of the slackcontext values for gathering this now!

- ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
+ ResolveLogstashHost(ctx, clients.Config.APIHostResolved)

clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).
Return("logstash host")

manifestMock := &app.ManifestMockObject{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/app/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func prepareCommonDeleteMocks(t *testing.T, cf *shared.ClientFactory, cm *shared

cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
Return("api host")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).
Return("logstash host")

// Mock list command
Expand Down
2 changes: 1 addition & 1 deletion cmd/app/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func prepareCommonUninstallMocks(ctx context.Context, clients *shared.ClientFact
// Mock API calls
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
Return("api host")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).
Return("logstash host")

clientsMock.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
Expand Down
4 changes: 2 additions & 2 deletions cmd/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func handleAuthRemoval(ctx context.Context, clients *shared.ClientFactory, auth

// Update the API Host and Logstash Host to be the selected/default auth
clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, &auth)
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved)

// First, try to revoke the xoxe-xoxp (auth) token credential
var xoxpToken = auth.Token
Expand All @@ -118,7 +118,7 @@ func handleAuthRemoval(ctx context.Context, clients *shared.ClientFactory, auth

// Update the API Host and Logstash Host to be the selected/default auth
clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, nil)
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved)

return nil
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/auth/logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLogoutCommand(t *testing.T) {
CmdArgs: []string{"--all"},
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil)
clientsMock.Auth.On("RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].Token).Return(nil)
clientsMock.Auth.On("RevokeToken", mock.Anything, fakeAuthsByTeamSlice[0].RefreshToken).Return(nil)
Expand All @@ -61,7 +61,7 @@ func TestLogoutCommand(t *testing.T) {
CmdArgs: []string{"--team", "team1"},
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil)
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
Flag: clientsMock.Config.Flags.Lookup("team"),
Expand All @@ -85,7 +85,7 @@ func TestLogoutCommand(t *testing.T) {
CmdArgs: []string{"--team", "T2"},
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
Flag: clientsMock.Config.Flags.Lookup("team"),
})).Return(iostreams.SelectPromptResponse{
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestLogoutCommand(t *testing.T) {
CmdArgs: []string{},
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("Auths", mock.Anything).Return(fakeAuthsByTeamSlice, nil)
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an authorization to revoke", []string{
FormatAuthLabel(fakeAuthsByTeamSlice[0]),
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestLogoutCommand(t *testing.T) {
CmdArgs: []string{},
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("api.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("logstash.slack.com")
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
fakeAuthsByTeamSlice[0],
}, nil)
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob

// Init clients that use flags
clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, nil)
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, version.Raw())
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved)

// Init System ID
if systemID, err := clients.Config.SystemConfig.InitSystemID(ctx); err != nil {
Expand Down Expand Up @@ -296,8 +296,6 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob
// Init configurations
clients.Config.LoadExperiments(ctx, clients.IO.PrintDebug)
style.ToggleLipgloss(clients.Config.WithExperimentOn(experiment.Lipgloss))
// TODO(slackcontext) Consolidate storing CLI version to slackcontext
clients.Config.Version = version.Raw()
Comment on lines -299 to -300
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 Removing the TODO to consolidate the version to slackcontext.


// The domain auths (token->domain) shouldn't change for the execution of the CLI so preload them into config!
clients.Config.DomainAuthTokens = clients.Auth().MapAuthTokensToDomains(ctx)
Expand Down
28 changes: 14 additions & 14 deletions cmd/sandbox/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "test-box", "test-box", "mypass", "", "", 0, "", int64(0), false).
Return("T123", "https://test-box.slack.com", nil)
cm.API.On("UsersInfo", mock.Anything, mock.Anything, mock.Anything).Return(&types.UserInfo{Profile: types.UserProfile{}}, nil)
Expand All @@ -73,7 +73,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "My Test Box", "my-test-box", "pass", "", "", 0, "", int64(0), false).
Return("T789", "https://my-test-box.slack.com", nil)

Expand All @@ -98,7 +98,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "tmp-box", "tmp-box", "pass", "", "", 0, "", mock.MatchedBy(func(v int64) bool { return v > 0 }), false).
Return("T111", "https://tmp-box.slack.com", nil)

Expand All @@ -122,7 +122,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "err-box", "err-box", "pass", "", "", 0, "", int64(0), false).
Return("", "", errors.New("api_error"))

Expand All @@ -145,7 +145,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "tpl-box", "tpl-box", "pass", "", "", 1, "", int64(0), false).
Return("T333", "https://tpl-box.slack.com", nil)

Expand All @@ -171,7 +171,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "partner-box", "partner-box", "pass", "", "", 0, "", int64(0), true).
Return("T555", "https://partner-box.slack.com", nil)

Expand All @@ -197,7 +197,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")

cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = []string{string(experiment.Sandboxes)}
Expand All @@ -221,7 +221,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "date-box", "date-box", "pass", "", "", 0, "", archiveEpoch, false).
Return("T222", "https://date-box.slack.com", nil)

Expand All @@ -247,7 +247,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")

cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = []string{string(experiment.Sandboxes)}
Expand All @@ -271,7 +271,7 @@ func TestCreateCommand(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")

cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = []string{string(experiment.Sandboxes)}
Expand Down Expand Up @@ -306,7 +306,7 @@ func setupCreateMocks(t *testing.T, ctx context.Context, cm *shared.ClientsMock,
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, name, domain, password, "", "", 0, "", archiveEpoch, partner).
Return("T222", "https://"+domain+".slack.com", nil)
cm.AddDefaultMocks()
Expand All @@ -319,7 +319,7 @@ func setupCreateAuthOnly(t *testing.T, ctx context.Context, cm *shared.ClientsMo
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = []string{string(experiment.Sandboxes)}
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
Expand Down Expand Up @@ -494,7 +494,7 @@ func Test_getTemplateID(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "tpl-box", "tpl-box", "pass", "", "", 1, "", int64(0), false).
Return("T333", "https://tpl-box.slack.com", nil)
cm.AddDefaultMocks()
Expand All @@ -519,7 +519,7 @@ func Test_getTemplateID(t *testing.T) {
testToken := "xoxb-test-token"
cm.Auth.On("AuthWithToken", mock.Anything, testToken).Return(types.SlackAuth{Token: testToken}, nil)
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).Return("https://api.slack.com")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything).Return("https://slackb.com/events/cli")
cm.API.On("CreateSandbox", mock.Anything, testToken, "tpl-box", "tpl-box", "pass", "", "", 1, "", int64(0), false).
Return("T333", "https://tpl-box.slack.com", nil)
cm.AddDefaultMocks()
Expand Down
Loading
Loading