Skip to content

Commit 6029cd4

Browse files
committed
pass tests
1 parent 7eab3bd commit 6029cd4

File tree

8 files changed

+122
-250
lines changed

8 files changed

+122
-250
lines changed

cli/deployment/config.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ func New(options *Options) *API {
286286
})
287287
})
288288
})
289-
r.Route("/flags", func(r chi.Router) {
289+
r.Route("/config", func(r chi.Router) {
290290
r.Use(apiKeyMiddleware)
291-
// r.Get("/deployment", api.deploymentFlags)
291+
r.Get("/deployment", api.deploymentConfig)
292292
})
293293
r.Route("/audit", func(r chi.Router) {
294294
r.Use(

coderd/flags.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package coderd
22

3-
// func (api *API) deploymentFlags(rw http.ResponseWriter, r *http.Request) {
4-
// if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentFlags) {
5-
// httpapi.Forbidden(rw)
6-
// return
7-
// }
8-
9-
// httpapi.Write(r.Context(), rw, http.StatusOK, deployment.RemoveSensitiveValues(*api.DeploymentFlags))
10-
// }
3+
import (
4+
"net/http"
5+
6+
"github.com/coder/coder/coderd/httpapi"
7+
"github.com/coder/coder/coderd/rbac"
8+
)
9+
10+
func (api *API) deploymentConfig(rw http.ResponseWriter, r *http.Request) {
11+
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentConfig) {
12+
httpapi.Forbidden(rw)
13+
return
14+
}
15+
16+
httpapi.Write(r.Context(), rw, http.StatusOK, api.DeploymentConfig)
17+
}

coderd/flags_test.go

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
package coderd_test
22

3-
const (
4-
secretValue = "********"
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/cli/deployment"
10+
"github.com/coder/coder/coderd/coderdtest"
11+
"github.com/coder/coder/testutil"
512
)
613

7-
// func TestDeploymentFlagSecrets(t *testing.T) {
8-
// t.Parallel()
9-
// hi := "hi"
10-
// ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
11-
// defer cancel()
12-
// df := deployment.Flags()
13-
// // check if copy works for non-secret values
14-
// df.AccessURL.Value = hi
15-
// // check if secrets are removed
16-
// df.OAuth2GithubClientSecret.Value = hi
17-
// df.OIDCClientSecret.Value = hi
18-
// df.PostgresURL.Value = hi
19-
// df.SCIMAuthHeader.Value = hi
14+
func TestDeploymentConfig(t *testing.T) {
15+
t.Parallel()
16+
hi := "hi"
17+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
18+
defer cancel()
19+
vip := deployment.NewViper()
20+
cfg, err := deployment.Config(vip)
21+
require.NoError(t, err)
22+
// values should be returned
23+
cfg.AccessURL = hi
24+
// values should not be returned
25+
cfg.OAuth2Github.ClientSecret = hi
26+
cfg.OIDC.ClientSecret = hi
27+
cfg.PostgresURL = hi
28+
cfg.SCIMAuthHeader = hi
2029

21-
// client := coderdtest.New(t, &coderdtest.Options{
22-
// DeploymentFlags: df,
23-
// })
24-
// _ = coderdtest.CreateFirstUser(t, client)
25-
// scrubbed, err := client.DeploymentFlags(ctx)
26-
// require.NoError(t, err)
27-
// // ensure df is unchanged
28-
// require.EqualValues(t, hi, df.OAuth2GithubClientSecret.Value)
29-
// // ensure normal values pass through
30-
// require.EqualValues(t, hi, scrubbed.AccessURL.Value)
31-
// // ensure secrets are removed
32-
// require.EqualValues(t, secretValue, scrubbed.OAuth2GithubClientSecret.Value)
33-
// require.EqualValues(t, secretValue, scrubbed.OIDCClientSecret.Value)
34-
// require.EqualValues(t, secretValue, scrubbed.PostgresURL.Value)
35-
// require.EqualValues(t, secretValue, scrubbed.SCIMAuthHeader.Value)
36-
// }
30+
client := coderdtest.New(t, &coderdtest.Options{
31+
DeploymentConfig: &cfg,
32+
})
33+
_ = coderdtest.CreateFirstUser(t, client)
34+
scrubbed, err := client.DeploymentConfig(ctx)
35+
require.NoError(t, err)
36+
// ensure normal values pass through
37+
require.EqualValues(t, hi, scrubbed.AccessURL)
38+
// ensure secrets are removed
39+
require.Empty(t, scrubbed.OAuth2Github.ClientSecret)
40+
require.Empty(t, scrubbed.OIDC.ClientSecret)
41+
require.Empty(t, scrubbed.PostgresURL)
42+
require.Empty(t, scrubbed.SCIMAuthHeader)
43+
}

coderd/rbac/object.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ var (
142142
Type: "license",
143143
}
144144

145-
// ResourceDeploymentFlags
146-
ResourceDeploymentFlags = Object{
147-
Type: "deployment_flags",
145+
// ResourceDeploymentConfig
146+
ResourceDeploymentConfig = Object{
147+
Type: "deployment_config",
148148
}
149149

150150
ResourceReplicas = Object{

0 commit comments

Comments
 (0)