(t *testing.T)
| 2085 | } |
| 2086 | |
| 2087 | func TestCreateWithGitAuth(t *testing.T) { |
| 2088 | t.Parallel() |
| 2089 | echoResponses := &echo.Responses{ |
| 2090 | Parse: echo.ParseComplete, |
| 2091 | ProvisionInit: echo.InitComplete, |
| 2092 | ProvisionPlan: echo.PlanComplete, |
| 2093 | ProvisionGraph: []*proto.Response{ |
| 2094 | { |
| 2095 | Type: &proto.Response_Graph{ |
| 2096 | Graph: &proto.GraphComplete{ |
| 2097 | ExternalAuthProviders: []*proto.ExternalAuthProviderResource{{Id: "github"}}, |
| 2098 | }, |
| 2099 | }, |
| 2100 | }, |
| 2101 | }, |
| 2102 | ProvisionApply: echo.ApplyComplete, |
| 2103 | } |
| 2104 | |
| 2105 | client := coderdtest.New(t, &coderdtest.Options{ |
| 2106 | ExternalAuthConfigs: []*externalauth.Config{{ |
| 2107 | InstrumentedOAuth2Config: &testutil.OAuth2Config{}, |
| 2108 | ID: "github", |
| 2109 | Regex: regexp.MustCompile(`github\.com`), |
| 2110 | Type: codersdk.EnhancedExternalAuthProviderGitHub.String(), |
| 2111 | DisplayName: "GitHub", |
| 2112 | }}, |
| 2113 | IncludeProvisionerDaemon: true, |
| 2114 | }) |
| 2115 | owner := coderdtest.CreateFirstUser(t, client) |
| 2116 | member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) |
| 2117 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, echoResponses) |
| 2118 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 2119 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
| 2120 | |
| 2121 | inv, root := clitest.New(t, "create", "my-workspace", "--template", template.Name) |
| 2122 | clitest.SetupConfig(t, member, root) |
| 2123 | pty := ptytest.New(t).Attach(inv) |
| 2124 | clitest.Start(t, inv) |
| 2125 | |
| 2126 | pty.ExpectMatch("You must authenticate with GitHub to create a workspace") |
| 2127 | resp := coderdtest.RequestExternalAuthCallback(t, "github", member) |
| 2128 | _ = resp.Body.Close() |
| 2129 | require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode) |
| 2130 | pty.ExpectMatch("Confirm create?") |
| 2131 | pty.WriteLine("yes") |
| 2132 | } |
nothing calls this directly
no test coverage detected