Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- go formatted cmd directory & make profile public - remove configure command moved under stripe auth --interactive - Create login command - Break cli configuration into own file (config.go) - test files with @jmuia-stripe
- Loading branch information
1 parent
999b591
commit 4016f72
Showing
18 changed files
with
512 additions
and
190 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/stripe/stripe-cli/login" | ||
"github.com/stripe/stripe-cli/validators" | ||
) | ||
|
||
type loginCmd struct { | ||
cmd *cobra.Command | ||
interactive bool | ||
url string | ||
} | ||
|
||
func newLoginCmd() *loginCmd { | ||
lc := &loginCmd{} | ||
|
||
lc.cmd = &cobra.Command{ | ||
Use: "login", | ||
Args: validators.NoArgs, | ||
Short: "Log into your Stripe account", | ||
Long: `Log into your Stripe account to write your configuration file`, | ||
RunE: lc.runLoginCmd, | ||
} | ||
lc.cmd.Flags().BoolVarP(&lc.interactive, "interactive", "i", false, "interactive configuration mode") | ||
lc.cmd.Flags().StringVarP(&lc.url, "url", "u", "", "Testing URL for login ") | ||
lc.cmd.Flags().MarkHidden("url") | ||
|
||
return lc | ||
} | ||
|
||
|
||
func (lc *loginCmd) runLoginCmd(cmd *cobra.Command, args []string) error { | ||
if lc.interactive { | ||
return login.InteractiveLogin(Profile) | ||
} | ||
return login.Login(lc.url, Profile) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stripe/stripe-cli/login" | ||
"github.com/stripe/stripe-cli/profile" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
) | ||
|
||
func TestLogin(t *testing.T) { | ||
configFile := filepath.Join(os.TempDir(), "stripe", "config.toml") | ||
p := profile.Profile{ | ||
Color: "auto", | ||
ConfigFile: configFile, | ||
LogLevel: "info", | ||
ProfileName: "tests", | ||
DeviceName: "st-testing", | ||
} | ||
|
||
|
||
|
||
var pollURL string | ||
var browserURL string | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if strings.Contains(r.URL.Path, "auth") { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "application/json") | ||
expectedLinks := login.Links{ | ||
BrowserURL: browserURL, | ||
PollURL: pollURL, | ||
VerificationCode: "dinosaur-pineapple-polkadot", | ||
} | ||
json.NewEncoder(w).Encode(expectedLinks) | ||
} | ||
if strings.Contains(r.URL.Path,"browser") { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "text/html") | ||
w.Write([]byte("<HTML></HTML>")) | ||
|
||
} | ||
if strings.Contains(r.URL.Path,"poll") { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "application/json") | ||
data := []byte(`{"redeemed": true, "account_id": "acct_123", "testmode_key_secret": "sk_test_1234"}`) | ||
fmt.Println(string(data)) | ||
w.Write(data) | ||
} | ||
})) | ||
defer ts.Close() | ||
|
||
authURL := fmt.Sprintf( "%s%s", ts.URL, "/auth") | ||
pollURL = fmt.Sprintf( "%s%s", ts.URL, "/poll") | ||
browserURL = fmt.Sprintf( "%s%s", ts.URL, "/browser") | ||
|
||
err := login.Login(authURL, p) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.