mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-07 21:08:12 +00:00
1382ab41e7
* wip * fix: fix util imports * fix: fix bootstrap import issues * fix: fix cli imports * fix: context controller * fix: use new context in user controller * fix: fix imports and context in proxy controller * fix: fix oauth and oidc controller imports and context * feat: finalize context functionality * refactor: simplify acls checking logic by passing the entire acl struct * chore: rename get basic auth to encode basic auth for clarity * fix: fix controller tests * tests: fix service tests * tests: fix utils tests * tests: move to testify for testing in utils * fix: fix config reference generator * tests: add tests for context parsing * tests: add tests for context middleware * tests: remove error wrapper from context tests * tests: fix log wrapper tests * fix: fix verion setting in cd and dockerfiles * fix: review comments batch 1 * fix: review comments batch 2 * fix: review comments batch 3 * fix: delete totp pending session cookie on totp success * tests: fix user controller tests * fix: don't audit login too early * fix: own comments
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package decoders_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tinyauthapp/tinyauth/internal/model"
|
|
"github.com/tinyauthapp/tinyauth/internal/utils/decoders"
|
|
)
|
|
|
|
func TestDecodeLabels(t *testing.T) {
|
|
// Variables
|
|
expected := model.Apps{
|
|
Apps: map[string]model.App{
|
|
"foo": {
|
|
Config: model.AppConfig{
|
|
Domain: "example.com",
|
|
},
|
|
Users: model.AppUsers{
|
|
Allow: "user1,user2",
|
|
Block: "user3",
|
|
},
|
|
OAuth: model.AppOAuth{
|
|
Whitelist: "somebody@example.com",
|
|
Groups: "group3",
|
|
},
|
|
IP: model.AppIP{
|
|
Allow: []string{"10.71.0.1/24", "10.71.0.2"},
|
|
Block: []string{"10.10.10.10", "10.0.0.0/24"},
|
|
Bypass: []string{"192.168.1.1"},
|
|
},
|
|
Response: model.AppResponse{
|
|
Headers: []string{"X-Foo=Bar", "X-Baz=Qux"},
|
|
BasicAuth: model.AppBasicAuth{
|
|
Username: "admin",
|
|
Password: "password",
|
|
PasswordFile: "/path/to/passwordfile",
|
|
},
|
|
},
|
|
Path: model.AppPath{
|
|
Allow: "/public",
|
|
Block: "/private",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
test := map[string]string{
|
|
"tinyauth.apps.foo.config.domain": "example.com",
|
|
"tinyauth.apps.foo.users.allow": "user1,user2",
|
|
"tinyauth.apps.foo.users.block": "user3",
|
|
"tinyauth.apps.foo.oauth.whitelist": "somebody@example.com",
|
|
"tinyauth.apps.foo.oauth.groups": "group3",
|
|
"tinyauth.apps.foo.ip.allow": "10.71.0.1/24,10.71.0.2",
|
|
"tinyauth.apps.foo.ip.block": "10.10.10.10,10.0.0.0/24",
|
|
"tinyauth.apps.foo.ip.bypass": "192.168.1.1",
|
|
"tinyauth.apps.foo.response.headers": "X-Foo=Bar,X-Baz=Qux",
|
|
"tinyauth.apps.foo.response.basicauth.username": "admin",
|
|
"tinyauth.apps.foo.response.basicauth.password": "password",
|
|
"tinyauth.apps.foo.response.basicauth.passwordfile": "/path/to/passwordfile",
|
|
"tinyauth.apps.foo.path.allow": "/public",
|
|
"tinyauth.apps.foo.path.block": "/private",
|
|
}
|
|
|
|
// Test
|
|
result, err := decoders.DecodeLabels[model.Apps](test, "apps")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, expected, result)
|
|
}
|