MCPcopy Index your code
hub / github.com/coder/coder / TestServer_ExternalAuthGitHubDefaultProvider

Function TestServer_ExternalAuthGitHubDefaultProvider

cli/server_test.go:1884–2030  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // This test sets environment variables.

(t *testing.T)

Source from the content-addressed store, hash-verified

1882
1883//nolint:tparallel,paralleltest // This test sets environment variables.
1884func TestServer_ExternalAuthGitHubDefaultProvider(t *testing.T) {
1885 type testCase struct {
1886 name string
1887 args []string
1888 env map[string]string
1889 createUserPreStart bool
1890 expectedProviders []string
1891 }
1892
1893 run := func(t *testing.T, tc testCase) {
1894 ctx := testutil.Context(t, testutil.WaitLong)
1895
1896 unsetPrefixedEnv := func(prefix string) {
1897 t.Helper()
1898 for _, envVar := range os.Environ() {
1899 envKey, _, found := strings.Cut(envVar, "=")
1900 if !found || !strings.HasPrefix(envKey, prefix) {
1901 continue
1902 }
1903 value, had := os.LookupEnv(envKey)
1904 require.True(t, had)
1905 require.NoError(t, os.Unsetenv(envKey))
1906 keyCopy := envKey
1907 valueCopy := value
1908 t.Cleanup(func() {
1909 // This is for setting/unsetting a number of prefixed env vars.
1910 // t.Setenv doesn't cover this use case.
1911 // nolint:usetesting
1912 _ = os.Setenv(keyCopy, valueCopy)
1913 })
1914 }
1915 }
1916 unsetPrefixedEnv("CODER_EXTERNAL_AUTH_")
1917 unsetPrefixedEnv("CODER_GITAUTH_")
1918
1919 dbURL, err := dbtestutil.Open(t)
1920 require.NoError(t, err)
1921 db, _ := dbtestutil.NewDB(t, dbtestutil.WithURL(dbURL))
1922
1923 const (
1924 existingUserEmail = "existing-user@coder.com"
1925 existingUserUsername = "existing-user"
1926 existingUserPassword = "SomeSecurePassword!"
1927 )
1928 if tc.createUserPreStart {
1929 hashedPassword, err := userpassword.Hash(existingUserPassword)
1930 require.NoError(t, err)
1931 _ = dbgen.User(t, db, database.User{
1932 Email: existingUserEmail,
1933 Username: existingUserUsername,
1934 HashedPassword: []byte(hashedPassword),
1935 })
1936 }
1937
1938 args := []string{
1939 "server",
1940 "--postgres-url", dbURL,
1941 "--http-address", ":0",

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
OpenFunction · 0.92
NewDBFunction · 0.92
WithURLFunction · 0.92
HashFunction · 0.92
UserFunction · 0.92
NewFunction · 0.92
StartFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
SetenvMethod · 0.80
LoginWithPasswordMethod · 0.80

Tested by

no test coverage detected