mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
* Add git auth providers schema * Pipe git auth providers to the schema * Add git auth providers to the API * Add gitauth endpoint to query authenticated state * Add endpoint to query git state * Use BroadcastChannel to automatically authenticate with Git * Add error validation for submitting the create workspace form * Fix panic on template dry-run * Add tests for the template version Git auth endpoint * Show error if no gitauth is configured * Add gitauth to cliui * Fix unused method receiver * Fix linting errors * Fix dbauthz querier test * Fix make gen * Add JavaScript test for git auth * Fix bad error message * Fix provisionerd test race See https://github.com/coder/coder/actions/runs/4277960646/jobs/7447232814 * Fix requested changes * Add comment to CreateWorkspacePageView
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package cliui_test
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/coder/coder/cli/cliui"
|
|
"github.com/coder/coder/codersdk"
|
|
"github.com/coder/coder/pty/ptytest"
|
|
"github.com/coder/coder/testutil"
|
|
)
|
|
|
|
func TestGitAuth(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
|
defer cancel()
|
|
|
|
ptty := ptytest.New(t)
|
|
cmd := &cobra.Command{
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
var fetched atomic.Bool
|
|
return cliui.GitAuth(cmd.Context(), cmd.OutOrStdout(), cliui.GitAuthOptions{
|
|
Fetch: func(ctx context.Context) ([]codersdk.TemplateVersionGitAuth, error) {
|
|
defer fetched.Store(true)
|
|
return []codersdk.TemplateVersionGitAuth{{
|
|
ID: "github",
|
|
Type: codersdk.GitProviderGitHub,
|
|
Authenticated: fetched.Load(),
|
|
AuthenticateURL: "https://example.com/gitauth/github?redirect=" + url.QueryEscape("/gitauth?notify"),
|
|
}}, nil
|
|
},
|
|
FetchInterval: time.Millisecond,
|
|
})
|
|
},
|
|
}
|
|
cmd.SetOutput(ptty.Output())
|
|
cmd.SetIn(ptty.Input())
|
|
done := make(chan struct{})
|
|
go func() {
|
|
defer close(done)
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
}()
|
|
ptty.ExpectMatchContext(ctx, "You must authenticate with")
|
|
ptty.ExpectMatchContext(ctx, "https://example.com/gitauth/github")
|
|
ptty.ExpectMatchContext(ctx, "Successfully authenticated with GitHub")
|
|
<-done
|
|
}
|