mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-02-19 19:44:16 +02:00
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>
This commit is contained in:
parent
b8ae6448e1
commit
f88f09f962
14
.devcontainer/Dockerfile
Normal file
14
.devcontainer/Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/go:0-1.19
|
||||
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
pre-commit \
|
||||
vim \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& mkdir -p /go/pkg \
|
||||
&& chmod -R a+w /go/pkg
|
||||
|
||||
WORKDIR /workspace
|
45
.devcontainer/devcontainer.json
Normal file
45
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "oauth2-proxy Dev",
|
||||
"context": "..",
|
||||
"dockerFile": "./Dockerfile",
|
||||
"postCreateCommand": "pre-commit install && go mod download",
|
||||
"containerEnv": { "DEVCONTAINER": "1" },
|
||||
"appPort": ["4180:4180"],
|
||||
"runArgs": ["-e", "GIT_EDITOR=code --wait"],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"golang.go",
|
||||
"ms-vscode.makefile-tools",
|
||||
"visualstudioexptteam.vscodeintellicode",
|
||||
"redhat.vscode-yaml",
|
||||
"esbenp.prettier-vscode",
|
||||
"GitHub.vscode-pull-request-github"
|
||||
],
|
||||
"settings": {
|
||||
"editor.formatOnPaste": false,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"yaml.customTags": [
|
||||
"!input scalar",
|
||||
"!secret scalar",
|
||||
"!include_dir_named scalar",
|
||||
"!include_dir_list scalar",
|
||||
"!include_dir_merge_list scalar",
|
||||
"!include_dir_merge_named scalar"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/docker-in-docker": {},
|
||||
"ghcr.io/devcontainers/features/common-utils": {
|
||||
"configureZshAsDefaultShell": true,
|
||||
"username": "vscode",
|
||||
"userUid": 1000,
|
||||
"userGid": 1000
|
||||
},
|
||||
"ghcr.io/devcontainers/features/kubectl-helm-minikube": {}
|
||||
}
|
||||
}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -18,7 +18,8 @@ c.out
|
||||
_obj
|
||||
_test
|
||||
.idea/
|
||||
.vscode/
|
||||
.vscode/*
|
||||
!/.vscode/tasks.json
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
|
13
.pre-commit-config.yaml
Normal file
13
.pre-commit-config.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: check-added-large-files
|
||||
- repo: https://github.com/dnephin/pre-commit-golang
|
||||
rev: v0.5.0
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
- id: go-build
|
36
.vscode/launch.json
vendored
Normal file
36
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "OAuth2 Proxy for Dex",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}",
|
||||
"args": [
|
||||
"--config", "contrib/local-environment/oauth2-proxy.cfg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "OAuth2 Proxy for Keycloak",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}",
|
||||
"args": [
|
||||
"--config", "contrib/local-environment/oauth2-proxy-keycloak.cfg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "OAuth2 Proxy with Alpha Config",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}",
|
||||
"args": [
|
||||
"--config", "contrib/local-environment/oauth2-proxy-alpha-config.cfg",
|
||||
"--alpha-config", "contrib/local-environment/oauth2-proxy-alpha-config.yaml"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
76
.vscode/tasks.json
vendored
Normal file
76
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Run oauth2-proxy",
|
||||
"type": "shell",
|
||||
"command": "./oauth2-proxy --config contrib/local-environment/oauth2-proxy.cfg --alpha-config contrib/local-environment/oauth2-proxy-alpha0config.cfg",
|
||||
"dependsOn": ["Build"],
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Test",
|
||||
"type": "shell",
|
||||
"command": "make test",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Ruff",
|
||||
"type": "shell",
|
||||
"command": "pre-commit run ruff --all-files",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "golint",
|
||||
"type": "shell",
|
||||
"command": "make lint",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build",
|
||||
"type": "shell",
|
||||
"command": "make build",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -26,9 +27,13 @@ var _ = Describe("Server", func() {
|
||||
expectedErr error
|
||||
expectHTTPListener bool
|
||||
expectTLSListener bool
|
||||
ipv6 bool
|
||||
}
|
||||
|
||||
DescribeTable("When creating the new server from the options", func(in *newServerTableInput) {
|
||||
if in.ipv6 {
|
||||
skipDevContainer()
|
||||
}
|
||||
srv, err := NewServer(in.opts)
|
||||
if in.expectedErr != nil {
|
||||
Expect(err).To(MatchError(ContainSubstring(in.expectedErr.Error())))
|
||||
@ -303,6 +308,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: true,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, with no TLS config", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -312,6 +318,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -325,6 +332,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with a both a ipv6 valid http and ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -339,6 +347,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: true,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid bind address scheme", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -348,6 +357,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up listener: listen (invalid, [::1]:0) failed: listen invalid: unknown network invalid"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid secure bind address scheme", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -361,6 +371,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid bind address port", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -370,6 +381,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up listener: listen (tcp, [::1]:a) failed: listen tcp: "),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid secure bind address port", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -383,6 +395,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up TLS listener: listen ([::1]:a) failed: listen tcp: "),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid TLS key", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -398,6 +411,7 @@ var _ = Describe("Server", func() {
|
||||
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"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 invalid TLS cert", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -413,6 +427,7 @@ var _ = Describe("Server", func() {
|
||||
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"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 address, with no TLS key", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -425,6 +440,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 address, with no TLS cert", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -437,6 +453,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("when the ipv6 bind address is prefixed with the http scheme", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -446,6 +463,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: true,
|
||||
expectTLSListener: false,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("when the ipv6 secure bind address is prefixed with the https scheme", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -459,6 +477,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -473,6 +492,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -487,6 +507,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -504,6 +525,7 @@ var _ = Describe("Server", func() {
|
||||
expectedErr: nil,
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
|
||||
opts: Opts{
|
||||
@ -521,6 +543,7 @@ var _ = Describe("Server", func() {
|
||||
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\""),
|
||||
expectHTTPListener: false,
|
||||
expectTLSListener: true,
|
||||
ipv6: true,
|
||||
}),
|
||||
)
|
||||
})
|
||||
@ -738,6 +761,7 @@ var _ = Describe("Server", func() {
|
||||
var listenAddr string
|
||||
|
||||
BeforeEach(func() {
|
||||
skipDevContainer()
|
||||
var err error
|
||||
srv, err = NewServer(Opts{
|
||||
Handler: handler,
|
||||
@ -788,6 +812,7 @@ var _ = Describe("Server", func() {
|
||||
var secureListenAddr string
|
||||
|
||||
BeforeEach(func() {
|
||||
skipDevContainer()
|
||||
var err error
|
||||
srv, err = NewServer(Opts{
|
||||
Handler: handler,
|
||||
@ -857,6 +882,7 @@ var _ = Describe("Server", func() {
|
||||
var listenAddr, secureListenAddr string
|
||||
|
||||
BeforeEach(func() {
|
||||
skipDevContainer()
|
||||
var err error
|
||||
srv, err = NewServer(Opts{
|
||||
Handler: handler,
|
||||
@ -965,3 +991,9 @@ var _ = Describe("Server", func() {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
func skipDevContainer() {
|
||||
if os.Getenv("DEVCONTAINER") != "" {
|
||||
Skip("Skipping testing in DevContainer environment")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user