mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-01 09:32:35 +02:00
fixes some tests
This commit is contained in:
parent
1eb3cb3ddb
commit
41dbcba815
7 changed files with 14 additions and 23 deletions
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||||
|
@ -227,7 +226,7 @@ func TestOIDCCallbackHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tt.wantStatus == http.StatusTemporaryRedirect {
|
if tt.wantStatus == http.StatusTemporaryRedirect {
|
||||||
setCookie := E.Must(http.ParseSetCookie(w.Header().Get("Set-Cookie")))
|
setCookie := Must(http.ParseSetCookie(w.Header().Get("Set-Cookie")))
|
||||||
ExpectEqual(t, setCookie.Name, defaultAuth.TokenCookieName())
|
ExpectEqual(t, setCookie.Name, defaultAuth.TokenCookieName())
|
||||||
ExpectTrue(t, setCookie.Value != "")
|
ExpectTrue(t, setCookie.Value != "")
|
||||||
ExpectEqual(t, setCookie.Path, "/")
|
ExpectEqual(t, setCookie.Path, "/")
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
|
||||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
@ -17,7 +16,7 @@ import (
|
||||||
func newMockUserPassAuth() *UserPassAuth {
|
func newMockUserPassAuth() *UserPassAuth {
|
||||||
return &UserPassAuth{
|
return &UserPassAuth{
|
||||||
username: "username",
|
username: "username",
|
||||||
pwdHash: E.Must(bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost)),
|
pwdHash: Must(bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost)),
|
||||||
secret: []byte("abcdefghijklmnopqrstuvwxyz"),
|
secret: []byte("abcdefghijklmnopqrstuvwxyz"),
|
||||||
tokenTTL: time.Hour,
|
tokenTTL: time.Hour,
|
||||||
}
|
}
|
||||||
|
@ -97,13 +96,13 @@ func TestUserPassLoginCallbackHandler(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Host: "app.example.com",
|
Host: "app.example.com",
|
||||||
Body: io.NopCloser(bytes.NewReader(E.Must(json.Marshal(tt.creds)))),
|
Body: io.NopCloser(bytes.NewReader(Must(json.Marshal(tt.creds)))),
|
||||||
}
|
}
|
||||||
auth.LoginCallbackHandler(w, req)
|
auth.LoginCallbackHandler(w, req)
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
ExpectEqual(t, w.Code, http.StatusUnauthorized)
|
ExpectEqual(t, w.Code, http.StatusUnauthorized)
|
||||||
} else {
|
} else {
|
||||||
setCookie := E.Must(http.ParseSetCookie(w.Header().Get("Set-Cookie")))
|
setCookie := Must(http.ParseSetCookie(w.Header().Get("Set-Cookie")))
|
||||||
ExpectTrue(t, setCookie.Name == auth.TokenCookieName())
|
ExpectTrue(t, setCookie.Name == auth.TokenCookieName())
|
||||||
ExpectTrue(t, setCookie.Value != "")
|
ExpectTrue(t, setCookie.Value != "")
|
||||||
ExpectEqual(t, setCookie.Domain, "example.com")
|
ExpectEqual(t, setCookie.Domain, "example.com")
|
||||||
|
|
|
@ -40,13 +40,6 @@ func From(err error) Error {
|
||||||
return &baseError{err}
|
return &baseError{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Must[T any](v T, err error) T {
|
|
||||||
if err != nil {
|
|
||||||
LogPanic("must failed", err)
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func Join(errors ...error) Error {
|
func Join(errors ...error) Error {
|
||||||
n := 0
|
n := 0
|
||||||
for _, err := range errors {
|
for _, err := range errors {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
|
||||||
. "github.com/yusing/go-proxy/internal/net/http/accesslog"
|
. "github.com/yusing/go-proxy/internal/net/http/accesslog"
|
||||||
"github.com/yusing/go-proxy/internal/task"
|
"github.com/yusing/go-proxy/internal/task"
|
||||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||||
|
@ -30,7 +29,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTask = task.RootTask("test", false)
|
testTask = task.RootTask("test", false)
|
||||||
testURL = E.Must(url.Parse("http://" + host + uri))
|
testURL = Must(url.Parse("http://" + host + uri))
|
||||||
req = &http.Request{
|
req = &http.Request{
|
||||||
RemoteAddr: remote,
|
RemoteAddr: remote,
|
||||||
Method: method,
|
Method: method,
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestBuild(t *testing.T) {
|
||||||
errs := E.NewBuilder("")
|
errs := E.NewBuilder("")
|
||||||
middlewares := BuildMiddlewaresFromYAML("", testMiddlewareCompose, errs)
|
middlewares := BuildMiddlewaresFromYAML("", testMiddlewareCompose, errs)
|
||||||
ExpectNoError(t, errs.Error())
|
ExpectNoError(t, errs.Error())
|
||||||
E.Must(json.MarshalIndent(middlewares, "", " "))
|
Must(json.MarshalIndent(middlewares, "", " "))
|
||||||
// t.Log(string(data))
|
// t.Log(string(data))
|
||||||
// TODO: test
|
// TODO: test
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
E "github.com/yusing/go-proxy/internal/error"
|
||||||
"github.com/yusing/go-proxy/internal/net/http/reverseproxy"
|
"github.com/yusing/go-proxy/internal/net/http/reverseproxy"
|
||||||
"github.com/yusing/go-proxy/internal/net/types"
|
"github.com/yusing/go-proxy/internal/net/types"
|
||||||
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed test_data/sample_headers.json
|
//go:embed test_data/sample_headers.json
|
||||||
|
@ -95,13 +96,13 @@ type testArgs struct {
|
||||||
|
|
||||||
func (args *testArgs) setDefaults() {
|
func (args *testArgs) setDefaults() {
|
||||||
if args.reqURL == nil {
|
if args.reqURL == nil {
|
||||||
args.reqURL = E.Must(types.ParseURL("https://example.com"))
|
args.reqURL = Must(types.ParseURL("https://example.com"))
|
||||||
}
|
}
|
||||||
if args.reqMethod == "" {
|
if args.reqMethod == "" {
|
||||||
args.reqMethod = http.MethodGet
|
args.reqMethod = http.MethodGet
|
||||||
}
|
}
|
||||||
if args.upstreamURL == nil {
|
if args.upstreamURL == nil {
|
||||||
args.upstreamURL = E.Must(types.ParseURL("https://10.0.0.1:8443")) // dummy url, no actual effect
|
args.upstreamURL = Must(types.ParseURL("https://10.0.0.1:8443")) // dummy url, no actual effect
|
||||||
}
|
}
|
||||||
if args.respHeaders == nil {
|
if args.respHeaders == nil {
|
||||||
args.respHeaders = http.Header{}
|
args.respHeaders = http.Header{}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
D "github.com/yusing/go-proxy/internal/docker"
|
D "github.com/yusing/go-proxy/internal/docker"
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
|
||||||
"github.com/yusing/go-proxy/internal/route"
|
"github.com/yusing/go-proxy/internal/route"
|
||||||
T "github.com/yusing/go-proxy/internal/route/types"
|
T "github.com/yusing/go-proxy/internal/route/types"
|
||||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||||
|
@ -31,7 +30,7 @@ func makeRoutes(cont *types.Container, dockerHostIP ...string) route.Routes {
|
||||||
host = client.DefaultDockerHost
|
host = client.DefaultDockerHost
|
||||||
}
|
}
|
||||||
p.name = "test"
|
p.name = "test"
|
||||||
routes := E.Must(p.routesFromContainerLabels(D.FromDocker(cont, host)))
|
routes := Must(p.routesFromContainerLabels(D.FromDocker(cont, host)))
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
r.Finalize()
|
r.Finalize()
|
||||||
}
|
}
|
||||||
|
@ -252,7 +251,7 @@ func TestDisableHealthCheck(t *testing.T) {
|
||||||
}
|
}
|
||||||
r, ok := makeRoutes(c)["a"]
|
r, ok := makeRoutes(c)["a"]
|
||||||
ExpectTrue(t, ok)
|
ExpectTrue(t, ok)
|
||||||
ExpectEqual(t, r.HealthCheck, nil)
|
ExpectFalse(t, r.UseHealthCheck())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicIPLocalhost(t *testing.T) {
|
func TestPublicIPLocalhost(t *testing.T) {
|
||||||
|
@ -348,7 +347,7 @@ func TestStreamDefaultValues(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExplicitExclude(t *testing.T) {
|
func TestExplicitExclude(t *testing.T) {
|
||||||
_, ok := makeRoutes(&types.Container{
|
r, ok := makeRoutes(&types.Container{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
D.LabelAliases: "a",
|
D.LabelAliases: "a",
|
||||||
|
@ -356,7 +355,8 @@ func TestExplicitExclude(t *testing.T) {
|
||||||
"proxy.a.no_tls_verify": "true",
|
"proxy.a.no_tls_verify": "true",
|
||||||
},
|
},
|
||||||
}, "")["a"]
|
}, "")["a"]
|
||||||
ExpectFalse(t, ok)
|
ExpectTrue(t, ok)
|
||||||
|
ExpectTrue(t, r.ShouldExclude())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImplicitExcludeDatabase(t *testing.T) {
|
func TestImplicitExcludeDatabase(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue