git.iko.soy/typeable/oauth2-proxy
on master help sign in
Improved dev environment (#2211)

* Improved dev env setup * Cleanup duplicate checks * Applied PR feedback * Updated go.mod/go.sum * go mod tidy * Update .devcontainer/devcontainer.json * Update pkg/http/server_test.go Co-authored-by: Jan Larwig <jan@larwig.com> * Create launch.json * Update .devcontainer/Dockerfile * Apply suggestions from code review --------- Co-authored-by: Jan Larwig <jan@larwig.com>

commitf88f09f962264c4073f343b901c58bcc9953411e authorKoen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com> dateSat 20 Jan 2024, 21:10 (3 years ago) parentb8ae644
7 files changed+218−1
.devcontainer/Dockerfile+14 .devcontainer/devcontainer.json+45 .gitignore+2−1 .pre-commit-config.yaml+13 .vscode/launch.json+36 .vscode/tasks.json+76 pkg/http/server_test.go+32
.devcontainer/Dockerfilenew file+14
@@ -0,0 +1,14 @@
1+FROM mcr.microsoft.com/vscode/devcontainers/go:0-1.19
2+
3+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4+
5+RUN apt-get update \
6+ && apt-get install -y --no-install-recommends \
7+ pre-commit \
8+ vim \
9+ && apt-get clean \
10+ && rm -rf /var/lib/apt/lists/* \
11+ && mkdir -p /go/pkg \
12+ && chmod -R a+w /go/pkg
13+
14+WORKDIR /workspace
.devcontainer/devcontainer.jsonnew file+45
@@ -0,0 +1,45 @@
1+{
2+ "name": "oauth2-proxy Dev",
3+ "context": "..",
4+ "dockerFile": "./Dockerfile",
5+ "postCreateCommand": "pre-commit install && go mod download",
6+ "containerEnv": { "DEVCONTAINER": "1" },
7+ "appPort": ["4180:4180"],
8+ "runArgs": ["-e", "GIT_EDITOR=code --wait"],
9+ "customizations": {
10+ "vscode": {
11+ "extensions": [
12+ "golang.go",
13+ "ms-vscode.makefile-tools",
14+ "visualstudioexptteam.vscodeintellicode",
15+ "redhat.vscode-yaml",
16+ "esbenp.prettier-vscode",
17+ "GitHub.vscode-pull-request-github"
18+ ],
19+ "settings": {
20+ "editor.formatOnPaste": false,
21+ "editor.formatOnSave": true,
22+ "editor.formatOnType": true,
23+ "files.trimTrailingWhitespace": true,
24+ "yaml.customTags": [
25+ "!input scalar",
26+ "!secret scalar",
27+ "!include_dir_named scalar",
28+ "!include_dir_list scalar",
29+ "!include_dir_merge_list scalar",
30+ "!include_dir_merge_named scalar"
31+ ]
32+ }
33+ }
34+ },
35+ "features": {
36+ "ghcr.io/devcontainers/features/docker-in-docker": {},
37+ "ghcr.io/devcontainers/features/common-utils": {
38+ "configureZshAsDefaultShell": true,
39+ "username": "vscode",
40+ "userUid": 1000,
41+ "userGid": 1000
42+ },
43+ "ghcr.io/devcontainers/features/kubectl-helm-minikube": {}
44+ }
45+}
.gitignore+2−1
@@ -18,7 +18,8 @@ c.out
1818_obj
1919_test
2020.idea/
21−.vscode/
21+.vscode/*
22+!/.vscode/tasks.json
2223
2324# Architecture specific extensions/prefixes
2425*.[568vq]
.pre-commit-config.yamlnew file+13
@@ -0,0 +1,13 @@
1+repos:
2+ - repo: https://github.com/pre-commit/pre-commit-hooks
3+ rev: v4.3.0
4+ hooks:
5+ - id: trailing-whitespace
6+ - id: end-of-file-fixer
7+ - id: check-yaml
8+ - id: check-added-large-files
9+ - repo: https://github.com/dnephin/pre-commit-golang
10+ rev: v0.5.0
11+ hooks:
12+ - id: golangci-lint
13+ - id: go-build
.vscode/launch.jsonnew file+36
@@ -0,0 +1,36 @@
1+{
2+ "version": "0.2.0",
3+ "configurations": [
4+ {
5+ "name": "OAuth2 Proxy for Dex",
6+ "type": "go",
7+ "request": "launch",
8+ "mode": "auto",
9+ "program": "${workspaceFolder}",
10+ "args": [
11+ "--config", "contrib/local-environment/oauth2-proxy.cfg"
12+ ]
13+ },
14+ {
15+ "name": "OAuth2 Proxy for Keycloak",
16+ "type": "go",
17+ "request": "launch",
18+ "mode": "auto",
19+ "program": "${workspaceFolder}",
20+ "args": [
21+ "--config", "contrib/local-environment/oauth2-proxy-keycloak.cfg"
22+ ]
23+ },
24+ {
25+ "name": "OAuth2 Proxy with Alpha Config",
26+ "type": "go",
27+ "request": "launch",
28+ "mode": "auto",
29+ "program": "${workspaceFolder}",
30+ "args": [
31+ "--config", "contrib/local-environment/oauth2-proxy-alpha-config.cfg",
32+ "--alpha-config", "contrib/local-environment/oauth2-proxy-alpha-config.yaml"
33+ ]
34+ }
35+ ]
36+}
.vscode/tasks.jsonnew file+76
@@ -0,0 +1,76 @@
1+{
2+ "version": "2.0.0",
3+ "tasks": [
4+ {
5+ "label": "Run oauth2-proxy",
6+ "type": "shell",
7+ "command": "./oauth2-proxy --config contrib/local-environment/oauth2-proxy.cfg --alpha-config contrib/local-environment/oauth2-proxy-alpha0config.cfg",
8+ "dependsOn": ["Build"],
9+ "group": {
10+ "kind": "test",
11+ "isDefault": true
12+ },
13+ "presentation": {
14+ "reveal": "always",
15+ "panel": "new"
16+ },
17+ "problemMatcher": []
18+ },
19+ {
20+ "label": "Test",
21+ "type": "shell",
22+ "command": "make test",
23+ "group": {
24+ "kind": "test",
25+ "isDefault": true
26+ },
27+ "presentation": {
28+ "reveal": "always",
29+ "panel": "new"
30+ },
31+ "problemMatcher": []
32+ },
33+ {
34+ "label": "Ruff",
35+ "type": "shell",
36+ "command": "pre-commit run ruff --all-files",
37+ "group": {
38+ "kind": "test",
39+ "isDefault": true
40+ },
41+ "presentation": {
42+ "reveal": "always",
43+ "panel": "new"
44+ },
45+ "problemMatcher": []
46+ },
47+ {
48+ "label": "golint",
49+ "type": "shell",
50+ "command": "make lint",
51+ "group": {
52+ "kind": "test",
53+ "isDefault": true
54+ },
55+ "presentation": {
56+ "reveal": "always",
57+ "panel": "new"
58+ },
59+ "problemMatcher": []
60+ },
61+ {
62+ "label": "Build",
63+ "type": "shell",
64+ "command": "make build",
65+ "group": {
66+ "kind": "test",
67+ "isDefault": true
68+ },
69+ "presentation": {
70+ "reveal": "always",
71+ "panel": "new"
72+ },
73+ "problemMatcher": []
74+ }
75+ ]
76+}
pkg/http/server_test.go+32
@@ -6,6 +6,7 @@ import (
66 "fmt"
77 "io"
88 "net/http"
9+ "os"
910
1011 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
1112 . "github.com/onsi/ginkgo"
@@ -26,9 +27,13 @@ var _ = Describe("Server", func() {
2627 expectedErr error
2728 expectHTTPListener bool
2829 expectTLSListener bool
30+ ipv6 bool
2931 }
3032
3133 DescribeTable("When creating the new server from the options", func(in *newServerTableInput) {
34+ if in.ipv6 {
35+ skipDevContainer()
36+ }
3237 srv, err := NewServer(in.opts)
3338 if in.expectedErr != nil {
3439 Expect(err).To(MatchError(ContainSubstring(in.expectedErr.Error())))
@@ -303,6 +308,7 @@ var _ = Describe("Server", func() {
303308 expectedErr: nil,
304309 expectHTTPListener: true,
305310 expectTLSListener: false,
311+ ipv6: true,
306312 }),
307313 Entry("with an ipv6 valid https bind address, with no TLS config", &newServerTableInput{
308314 opts: Opts{
@@ -312,6 +318,7 @@ var _ = Describe("Server", func() {
312318 expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
313319 expectHTTPListener: false,
314320 expectTLSListener: false,
321+ ipv6: true,
315322 }),
316323 Entry("with an ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
317324 opts: Opts{
@@ -325,6 +332,7 @@ var _ = Describe("Server", func() {
325332 expectedErr: nil,
326333 expectHTTPListener: false,
327334 expectTLSListener: true,
335+ ipv6: true,
328336 }),
329337 Entry("with a both a ipv6 valid http and ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
330338 opts: Opts{
@@ -339,6 +347,7 @@ var _ = Describe("Server", func() {
339347 expectedErr: nil,
340348 expectHTTPListener: true,
341349 expectTLSListener: true,
350+ ipv6: true,
342351 }),
343352 Entry("with an ipv6 invalid bind address scheme", &newServerTableInput{
344353 opts: Opts{
@@ -348,6 +357,7 @@ var _ = Describe("Server", func() {
348357 expectedErr: errors.New("error setting up listener: listen (invalid, [::1]:0) failed: listen invalid: unknown network invalid"),
349358 expectHTTPListener: false,
350359 expectTLSListener: false,
360+ ipv6: true,
351361 }),
352362 Entry("with an ipv6 invalid secure bind address scheme", &newServerTableInput{
353363 opts: Opts{
@@ -361,6 +371,7 @@ var _ = Describe("Server", func() {
361371 expectedErr: nil,
362372 expectHTTPListener: false,
363373 expectTLSListener: true,
374+ ipv6: true,
364375 }),
365376 Entry("with an ipv6 invalid bind address port", &newServerTableInput{
366377 opts: Opts{
@@ -370,6 +381,7 @@ var _ = Describe("Server", func() {
370381 expectedErr: errors.New("error setting up listener: listen (tcp, [::1]:a) failed: listen tcp: "),
371382 expectHTTPListener: false,
372383 expectTLSListener: false,
384+ ipv6: true,
373385 }),
374386 Entry("with an ipv6 invalid secure bind address port", &newServerTableInput{
375387 opts: Opts{
@@ -383,6 +395,7 @@ var _ = Describe("Server", func() {
383395 expectedErr: errors.New("error setting up TLS listener: listen ([::1]:a) failed: listen tcp: "),
384396 expectHTTPListener: false,
385397 expectTLSListener: false,
398+ ipv6: true,
386399 }),
387400 Entry("with an ipv6 invalid TLS key", &newServerTableInput{
388401 opts: Opts{
@@ -398,6 +411,7 @@ var _ = Describe("Server", func() {
398411 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not parse certificate data: tls: failed to find any PEM data in key input"),
399412 expectHTTPListener: false,
400413 expectTLSListener: false,
414+ ipv6: true,
401415 }),
402416 Entry("with an ipv6 invalid TLS cert", &newServerTableInput{
403417 opts: Opts{
@@ -413,6 +427,7 @@ var _ = Describe("Server", func() {
413427 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not parse certificate data: tls: failed to find any PEM data in certificate input"),
414428 expectHTTPListener: false,
415429 expectTLSListener: false,
430+ ipv6: true,
416431 }),
417432 Entry("with an ipv6 address, with no TLS key", &newServerTableInput{
418433 opts: Opts{
@@ -425,6 +440,7 @@ var _ = Describe("Server", func() {
425440 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
426441 expectHTTPListener: false,
427442 expectTLSListener: false,
443+ ipv6: true,
428444 }),
429445 Entry("with an ipv6 address, with no TLS cert", &newServerTableInput{
430446 opts: Opts{
@@ -437,6 +453,7 @@ var _ = Describe("Server", func() {
437453 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
438454 expectHTTPListener: false,
439455 expectTLSListener: false,
456+ ipv6: true,
440457 }),
441458 Entry("when the ipv6 bind address is prefixed with the http scheme", &newServerTableInput{
442459 opts: Opts{
@@ -446,6 +463,7 @@ var _ = Describe("Server", func() {
446463 expectedErr: nil,
447464 expectHTTPListener: true,
448465 expectTLSListener: false,
466+ ipv6: true,
449467 }),
450468 Entry("when the ipv6 secure bind address is prefixed with the https scheme", &newServerTableInput{
451469 opts: Opts{
@@ -459,6 +477,7 @@ var _ = Describe("Server", func() {
459477 expectedErr: nil,
460478 expectHTTPListener: false,
461479 expectTLSListener: true,
480+ ipv6: true,
462481 }),
463482 Entry("with an ipv6 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
464483 opts: Opts{
@@ -473,6 +492,7 @@ var _ = Describe("Server", func() {
473492 expectedErr: nil,
474493 expectHTTPListener: false,
475494 expectTLSListener: true,
495+ ipv6: true,
476496 }),
477497 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
478498 opts: Opts{
@@ -487,6 +507,7 @@ var _ = Describe("Server", func() {
487507 expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
488508 expectHTTPListener: false,
489509 expectTLSListener: true,
510+ ipv6: true,
490511 }),
491512 Entry("with an ipv6 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
492513 opts: Opts{
@@ -504,6 +525,7 @@ var _ = Describe("Server", func() {
504525 expectedErr: nil,
505526 expectHTTPListener: false,
506527 expectTLSListener: true,
528+ ipv6: true,
507529 }),
508530 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
509531 opts: Opts{
@@ -521,6 +543,7 @@ var _ = Describe("Server", func() {
521543 expectedErr: errors.New("error setting up TLS listener: could not parse cipher suites: unknown TLS cipher suite name specified \"TLS_RSA_WITH_RC4_64_SHA\""),
522544 expectHTTPListener: false,
523545 expectTLSListener: true,
546+ ipv6: true,
524547 }),
525548 )
526549 })
@@ -738,6 +761,7 @@ var _ = Describe("Server", func() {
738761 var listenAddr string
739762
740763 BeforeEach(func() {
764+ skipDevContainer()
741765 var err error
742766 srv, err = NewServer(Opts{
743767 Handler: handler,
@@ -788,6 +812,7 @@ var _ = Describe("Server", func() {
788812 var secureListenAddr string
789813
790814 BeforeEach(func() {
815+ skipDevContainer()
791816 var err error
792817 srv, err = NewServer(Opts{
793818 Handler: handler,
@@ -857,6 +882,7 @@ var _ = Describe("Server", func() {
857882 var listenAddr, secureListenAddr string
858883
859884 BeforeEach(func() {
885+ skipDevContainer()
860886 var err error
861887 srv, err = NewServer(Opts{
862888 Handler: handler,
@@ -965,3 +991,9 @@ var _ = Describe("Server", func() {
965991 )
966992 })
967993})
994+
995+func skipDevContainer() {
996+ if os.Getenv("DEVCONTAINER") != "" {
997+ Skip("Skipping testing in DevContainer environment")
998+ }
999+}