Skip to content
Merged
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
17 changes: 3 additions & 14 deletions cmd/externalauth/add_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func NewAddClientSecretCommand(clients *shared.ClientFactory) *cobra.Command {
"Add the client secret for an external provider of a workflow app.",
"",
"This secret will be used when initiating the OAuth2 flow.",
"",
"This command is supported for apps deployed to Slack managed infrastructure but",
"other apps can attempt to run the command with the --force flag.",
}, "\n"),
Example: style.ExampleCommandsf([]style.ExampleCommand{
{
Expand All @@ -67,18 +64,10 @@ func NewAddClientSecretCommand(clients *shared.ClientFactory) *cobra.Command {
return cmd
}

// preRunAddClientSecretCommand determines if the command is supported for a
// project and configures flags
func preRunAddClientSecretCommand(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error {
// preRunAddClientSecretCommand configures flags and validates the project directory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

praise: Renaming the doc comment from "determines if the command is supported for a project" to "configures flags and validates the project directory" matches what the function actually does post-ungate. Tight follow-through. 🤾🏻 💥

func preRunAddClientSecretCommand(_ context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error {
clients.Config.SetFlags(cmd)
err := cmdutil.IsValidProjectDirectory(clients)
if err != nil {
return err
}
if clients.Config.ForceFlag {
return nil
}
return cmdutil.IsSlackHostedProject(ctx, clients)
return cmdutil.IsValidProjectDirectory(clients)
}

// runAddClientSecretCommand adds a client secret to an authentication provider
Expand Down
70 changes: 1 addition & 69 deletions cmd/externalauth/add_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"errors"
"testing"

"github.com/slackapi/slack-cli/internal/app"
"github.com/slackapi/slack-cli/internal/config"
"github.com/slackapi/slack-cli/internal/iostreams"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/shared/types"
Expand All @@ -34,88 +32,22 @@ import (

func TestExternalAuthAddClientSecretCommandPreRun(t *testing.T) {
tests := map[string]struct {
mockFlagForce bool
mockManifestResponse types.SlackYaml
mockManifestError error
mockManifestSource config.ManifestSource
mockWorkingDirectory string
expectedError error
}{
"continues if the application is hosted on slack": {
mockManifestResponse: types.SlackYaml{
AppManifest: types.AppManifest{
Settings: &types.AppSettings{
FunctionRuntime: types.SlackHosted,
},
},
},
mockManifestError: nil,
"continues if the command is run in a valid project directory": {
mockWorkingDirectory: "/slack/path/to/project",
expectedError: nil,
},
"errors if the application is not hosted on slack": {
mockManifestResponse: types.SlackYaml{
AppManifest: types.AppManifest{
Settings: &types.AppSettings{
FunctionRuntime: types.Remote,
},
},
},
mockManifestError: nil,
mockManifestSource: config.ManifestSourceLocal,
mockWorkingDirectory: "/slack/path/to/project",
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
},
"continues if the force flag is used in a project": {
mockFlagForce: true,
mockWorkingDirectory: "/slack/path/to/project",
expectedError: nil,
},
"errors if the project manifest cannot be retrieved": {
mockManifestResponse: types.SlackYaml{},
mockManifestError: slackerror.New(slackerror.ErrSDKHookInvocationFailed),
mockManifestSource: config.ManifestSourceLocal,
mockWorkingDirectory: "/slack/path/to/project",
expectedError: slackerror.New(slackerror.ErrSDKHookInvocationFailed),
},
"errors if the command is not run in a project": {
mockManifestResponse: types.SlackYaml{},
mockManifestError: slackerror.New(slackerror.ErrSDKHookNotFound),
mockManifestSource: config.ManifestSourceLocal,
mockWorkingDirectory: "",
expectedError: slackerror.New(slackerror.ErrInvalidAppDirectory),
},
"errors if the manifest source is set to remote": {
mockManifestSource: config.ManifestSourceRemote,
mockWorkingDirectory: "/slack/path/to/project",
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
clientsMock := shared.NewClientsMock()
manifestMock := &app.ManifestMockObject{}
manifestMock.On(
"GetManifestLocal",
mock.Anything,
mock.Anything,
mock.Anything,
).Return(
tc.mockManifestResponse,
tc.mockManifestError,
)
clientsMock.AppClient.Manifest = manifestMock
projectConfigMock := config.NewProjectConfigMock()
projectConfigMock.On(
"GetManifestSource",
mock.Anything,
).Return(
tc.mockManifestSource,
nil,
)
clientsMock.Config.ProjectConfig = projectConfigMock
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(cf *shared.ClientFactory) {
cf.Config.ForceFlag = tc.mockFlagForce
cf.SDKConfig.WorkingDirectory = tc.mockWorkingDirectory
})
cmd := NewAddClientSecretCommand(clients)
Expand Down
Loading