Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/localstack/lstk/internal/env"
"github.com/localstack/lstk/internal/version"
)

type PlatformAPI interface {
Expand Down Expand Up @@ -73,10 +74,20 @@ func NewPlatformClient() *PlatformClient {
}

func (c *PlatformClient) CreateAuthRequest(ctx context.Context) (*AuthRequest, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", nil)
payload := map[string]string{
"actor": "cli-v2",
Comment thread
silv-io marked this conversation as resolved.
Outdated
"version": version.Version(),
Comment thread
silv-io marked this conversation as resolved.
}
body, err := json.Marshal(payload)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", bytes.NewReader(body))
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")

resp, err := c.httpClient.Do(req)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion test/integration/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ func createMockAPIServer(t *testing.T, licenseToken string, confirmed bool) *htt
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "POST" && r.URL.Path == "/v1/auth/request":
// Validate request payload
var payload map[string]string
err := json.NewDecoder(r.Body).Decode(&payload)
require.NoError(t, err, "failed to decode auth request payload")
assert.Equal(t, "cli-v2", payload["actor"], "actor should be cli-v2")
assert.NotEmpty(t, payload["version"], "version should not be empty")

w.WriteHeader(http.StatusCreated)
err := json.NewEncoder(w).Encode(map[string]string{
err = json.NewEncoder(w).Encode(map[string]string{
"id": authReqID,
"code": "TEST123",
"exchange_token": exchangeToken,
Expand Down