mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-04-13 01:07:57 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
def9e5aaaa | ||
|
|
6ffb52a5cd | ||
|
|
668348655f | ||
|
|
482b3c6b57 | ||
|
|
e451b3d62f | ||
|
|
5bada13919 | ||
|
|
9a6676b054 |
@@ -1,28 +0,0 @@
|
||||
# E2E Framework
|
||||
|
||||
[Project link](https://github.com/orgs/tinyauthapp/projects/1/views/1)
|
||||
|
||||
This is designed as an E2E framework to be able to test for changes in common proxy and application apps that tinyauth users are likely to use.
|
||||
|
||||
This is **not** designed to test functionality, it is a [Canary](https://en.wikipedia.org/wiki/Sentinel_species#Canaries). All functionailty testing is already done by Unit tests within the standard tinyauth PR / release workflows.
|
||||
|
||||
## Design
|
||||
|
||||
Primary testing is via Docker, although a minimal Kubernetes stack is also planned.
|
||||
|
||||
Initially this is being created to test the proxy connection, and ability to login.
|
||||
|
||||
Testing of endpoints and providers will be done via `traefik`.
|
||||
|
||||
It requires at least two endpoints, one will be `whoami` as an easy "is this working", but it also later requires an OIDC test (TBD), and a nested HTTP Auth (TBD).
|
||||
|
||||
It should test against all "known" Oauth providers (ie, the ones that are specifically mentioned in the documentation, including community supplied if possible).
|
||||
|
||||
> [!NOTE]
|
||||
> This requires having both Google and Github logins for the built-in providers, so security for those on a public E2E setup must be taken into account.
|
||||
|
||||
## Running
|
||||
|
||||
Run the <./test.sh> script, this handles everything for all tests.
|
||||
|
||||
TODO: Implement options to limit testing to specific proxies and auth services.
|
||||
@@ -1,10 +0,0 @@
|
||||
# This contains base apps without any proxy information
|
||||
|
||||
services:
|
||||
tinyauth:
|
||||
image: ${TINYAUTH_IMAGE:-ghcr.io/steveiliop56/tinyauth}:${TINYAUTH_IMAGE_TAG:-v5}
|
||||
environment:
|
||||
TINYAUTH_ANALYTICS_ENABLED: "false"
|
||||
TINYAUTH_APPURL: "https://tinyauth.${DOMAIN:-local}"
|
||||
volumes:
|
||||
- "./config:/data"
|
||||
@@ -1,44 +0,0 @@
|
||||
# This contains Traefik proxy versions
|
||||
# All apps must be prefixed by `traefik-`
|
||||
|
||||
services:
|
||||
traefik:
|
||||
container_name: traefik
|
||||
image: ${TRAEFIK_IMAGE:-traefik}:${TRAEFIK_IMAGE_TAG:-v3}
|
||||
networks:
|
||||
- e2e
|
||||
environment:
|
||||
TZ: "${TZ:-Europe/London}"
|
||||
PUID: "${PUID:-1000}"
|
||||
PGID: "${PGID:-1000}"
|
||||
UMASK: "000"
|
||||
command:
|
||||
- "--entryPoints.web.address=:80"
|
||||
- "--entryPoints.web.http.redirections.entryPoint.scheme=https"
|
||||
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
|
||||
- "--entryPoints.websecure.address=:443"
|
||||
- "--providers.docker=true"
|
||||
- "--providers.docker.endpoint=/var/run/docker.sock"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
- "./.ssl/key.pem:/run/secrets/key.pem:ro"
|
||||
- "./.ssl/cert.pem:/run/secrets/cert.pem:ro"
|
||||
- "./config:/etc/traefik"
|
||||
|
||||
traefik-tinyauth:
|
||||
container_name: traefik-tinyauth
|
||||
extends:
|
||||
file: ../compose.base.yaml
|
||||
service: tinyauth
|
||||
networks:
|
||||
e2e-external:
|
||||
e2e:
|
||||
aliases:
|
||||
- "traefik-tinyauth.$DOMAIN"
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.tinyauth.rule=Host(`tinyauth.$DOMAIN`)"
|
||||
- "traefik.http.services.tinyauth.loadbalancer.server.port=3000"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.address=http://tinyauth:3000/api/auth/traefik"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders=X-Forwarded-User"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.maxResponseBodySize=32768"
|
||||
@@ -1,53 +0,0 @@
|
||||
name: tinyauth-e2e
|
||||
|
||||
services:
|
||||
traefik-tinyauth:
|
||||
container_name: traefik-tinyauth
|
||||
extends:
|
||||
file: ../compose.base.yaml
|
||||
service: tinyauth
|
||||
networks:
|
||||
e2e-external:
|
||||
e2e:
|
||||
aliases:
|
||||
- "traefik-tinyauth.$DOMAIN"
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.tinyauth.rule=Host(`tinyauth.$DOMAIN`)"
|
||||
- "traefik.http.services.tinyauth.loadbalancer.server.port=3000"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.address=http://tinyauth:3000/api/auth/traefik"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders=X-Forwarded-User"
|
||||
- "traefik.http.middlewares.tinyauth.forwardauth.maxResponseBodySize=32768"
|
||||
|
||||
traefik-tinyauth-google:
|
||||
container_name: traefik-tinyauth-google
|
||||
secrets:
|
||||
- google_client_secret
|
||||
environment:
|
||||
TINYAUTH_OAUTH_PROVIDERS_GOOGLE_CLIENTID: "$GOOGLE_CLIENT_ID"
|
||||
TINYAUTH_OAUTH_PROVIDERS_GOOGLE_CLIENTSECRETFILE: "/run/secrets/google_client_secret"
|
||||
TINYAUTH_OAUTH_WHITELIST: "${WHITELIST:?Set the WHITELIST to your google email address!}"
|
||||
|
||||
whoami:
|
||||
image: traefik/whoami:latest
|
||||
networks:
|
||||
e2e:
|
||||
aliases:
|
||||
- "whoami.$DOMAIN"
|
||||
labels:
|
||||
traefik.enable: true
|
||||
traefik.http.routers.whoami.rule: Host(`whoami.$DOMAIN`)
|
||||
traefik.http.routers.whoami.middlewares: tinyauth
|
||||
|
||||
networks:
|
||||
e2e-external:
|
||||
name: "e2e-external"
|
||||
driver: bridge
|
||||
enable_ipv4: true
|
||||
enable_ipv6: true
|
||||
e2e:
|
||||
name: "e2e"
|
||||
driver: bridge
|
||||
internal: true
|
||||
enable_ipv4: true
|
||||
enable_ipv6: false
|
||||
@@ -1,2 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/go-querystring/query"
|
||||
|
||||
"github.com/steveiliop56/tinyauth/internal/service"
|
||||
"github.com/steveiliop56/tinyauth/internal/utils"
|
||||
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
|
||||
@@ -71,7 +70,6 @@ func (controller *OIDCController) SetupRoutes() {
|
||||
oidcGroup.POST("/authorize", controller.Authorize)
|
||||
oidcGroup.POST("/token", controller.Token)
|
||||
oidcGroup.GET("/userinfo", controller.Userinfo)
|
||||
oidcGroup.POST("/userinfo", controller.Userinfo)
|
||||
}
|
||||
|
||||
func (controller *OIDCController) GetClientInfo(c *gin.Context) {
|
||||
@@ -377,48 +375,22 @@ func (controller *OIDCController) Userinfo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var token string
|
||||
|
||||
authorization := c.GetHeader("Authorization")
|
||||
if authorization != "" {
|
||||
tokenType, bearerToken, ok := strings.Cut(authorization, " ")
|
||||
if !ok {
|
||||
tlog.App.Warn().Msg("OIDC userinfo accessed with malformed authorization header")
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid_request",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if strings.ToLower(tokenType) != "bearer" {
|
||||
tlog.App.Warn().Msg("OIDC userinfo accessed with invalid token type")
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid_request",
|
||||
})
|
||||
return
|
||||
}
|
||||
tokenType, token, ok := strings.Cut(authorization, " ")
|
||||
|
||||
token = bearerToken
|
||||
} else if c.Request.Method == http.MethodPost {
|
||||
if c.ContentType() != "application/x-www-form-urlencoded" {
|
||||
tlog.App.Warn().Msg("OIDC userinfo POST accessed with invalid content type")
|
||||
c.JSON(400, gin.H{
|
||||
"error": "invalid_request",
|
||||
})
|
||||
return
|
||||
}
|
||||
token = c.PostForm("access_token")
|
||||
if token == "" {
|
||||
tlog.App.Warn().Msg("OIDC userinfo POST accessed without access_token in body")
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid_request",
|
||||
})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !ok {
|
||||
tlog.App.Warn().Msg("OIDC userinfo accessed without authorization header")
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid_request",
|
||||
"error": "invalid_grant",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if strings.ToLower(tokenType) != "bearer" {
|
||||
tlog.App.Warn().Msg("OIDC userinfo accessed with invalid token type")
|
||||
c.JSON(401, gin.H{
|
||||
"error": "invalid_grant",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -435,128 +435,6 @@ func TestOIDCController(t *testing.T) {
|
||||
assert.False(t, ok, "Did not expect email claim in userinfo response")
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo forbids access with no authorization header",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("GET", "/api/oidc/userinfo", nil)
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 401, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_request", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo forbids access with malformed authorization header",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("GET", "/api/oidc/userinfo", nil)
|
||||
req.Header.Set("Authorization", "Bearer")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 401, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_request", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo forbids access with invalid token type",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("GET", "/api/oidc/userinfo", nil)
|
||||
req.Header.Set("Authorization", "Basic some-token")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 401, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_request", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo forbids access with empty bearer token",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("GET", "/api/oidc/userinfo", nil)
|
||||
req.Header.Set("Authorization", "Bearer ")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 401, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_grant", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo POST rejects missing access token in body",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("POST", "/api/oidc/userinfo", strings.NewReader(""))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 401, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_request", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo POST rejects wrong content type",
|
||||
middlewares: []gin.HandlerFunc{},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
req := httptest.NewRequest("POST", "/api/oidc/userinfo", strings.NewReader(`{"access_token":"some-token"}`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 400, recorder.Code)
|
||||
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(recorder.Body.Bytes(), &res)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "invalid_request", res["error"])
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure userinfo accepts access token via POST body",
|
||||
middlewares: []gin.HandlerFunc{
|
||||
simpleCtx,
|
||||
},
|
||||
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
|
||||
tokenTest, found := getTestByDescription("Ensure we can get a token with a valid request")
|
||||
assert.True(t, found, "Token test not found")
|
||||
tokenRecorder := httptest.NewRecorder()
|
||||
tokenTest(t, router, tokenRecorder)
|
||||
|
||||
var tokenRes map[string]any
|
||||
err := json.Unmarshal(tokenRecorder.Body.Bytes(), &tokenRes)
|
||||
assert.NoError(t, err)
|
||||
|
||||
accessToken := tokenRes["access_token"].(string)
|
||||
assert.NotEmpty(t, accessToken)
|
||||
|
||||
body := url.Values{}
|
||||
body.Set("access_token", accessToken)
|
||||
req := httptest.NewRequest("POST", "/api/oidc/userinfo", strings.NewReader(body.Encode()))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
router.ServeHTTP(recorder, req)
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
|
||||
var userInfoRes map[string]any
|
||||
err = json.Unmarshal(recorder.Body.Bytes(), &userInfoRes)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, ok := userInfoRes["sub"]
|
||||
assert.True(t, ok, "Expected sub claim in userinfo response")
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Ensure plain PKCE succeeds",
|
||||
middlewares: []gin.HandlerFunc{
|
||||
|
||||
@@ -24,7 +24,6 @@ var (
|
||||
"GET /api/oidc/clients",
|
||||
"POST /api/oidc/token",
|
||||
"GET /api/oidc/userinfo",
|
||||
"POST /api/oidc/userinfo",
|
||||
"GET /resources",
|
||||
"POST /api/user/login",
|
||||
"GET /.well-known/openid-configuration",
|
||||
|
||||
Reference in New Issue
Block a user