|
| 1 | +package decoders_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + "tinyauth/internal/config" |
| 7 | + "tinyauth/internal/utils/decoders" |
| 8 | +) |
| 9 | + |
| 10 | +func TestDecodeLabels(t *testing.T) { |
| 11 | + // Variables |
| 12 | + expected := config.Apps{ |
| 13 | + Apps: map[string]config.App{ |
| 14 | + "foo": { |
| 15 | + Config: config.AppConfig{ |
| 16 | + Domain: "example.com", |
| 17 | + }, |
| 18 | + Users: config.AppUsers{ |
| 19 | + Allow: "user1,user2", |
| 20 | + Block: "user3", |
| 21 | + }, |
| 22 | + OAuth: config.AppOAuth{ |
| 23 | + Whitelist: "somebody@example.com", |
| 24 | + Groups: "group3", |
| 25 | + }, |
| 26 | + IP: config.AppIP{ |
| 27 | + Allow: []string{"10.71.0.1/24", "10.71.0.2"}, |
| 28 | + Block: []string{"10.10.10.10", "10.0.0.0/24"}, |
| 29 | + Bypass: []string{"192.168.1.1"}, |
| 30 | + }, |
| 31 | + Response: config.AppResponse{ |
| 32 | + Headers: []string{"X-Foo=Bar", "X-Baz=Qux"}, |
| 33 | + BasicAuth: config.AppBasicAuth{ |
| 34 | + Username: "admin", |
| 35 | + Password: "password", |
| 36 | + PasswordFile: "/path/to/passwordfile", |
| 37 | + }, |
| 38 | + }, |
| 39 | + Path: config.AppPath{ |
| 40 | + Allow: "/public", |
| 41 | + Block: "/private", |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | + test := map[string]string{ |
| 47 | + "tinyauth.apps.foo.config.domain": "example.com", |
| 48 | + "tinyauth.apps.foo.users.allow": "user1,user2", |
| 49 | + "tinyauth.apps.foo.users.block": "user3", |
| 50 | + "tinyauth.apps.foo.oauth.whitelist": "somebody@example.com", |
| 51 | + "tinyauth.apps.foo.oauth.groups": "group3", |
| 52 | + "tinyauth.apps.foo.ip.allow": "10.71.0.1/24,10.71.0.2", |
| 53 | + "tinyauth.apps.foo.ip.block": "10.10.10.10,10.0.0.0/24", |
| 54 | + "tinyauth.apps.foo.ip.bypass": "192.168.1.1", |
| 55 | + "tinyauth.apps.foo.response.headers": "X-Foo=Bar,X-Baz=Qux", |
| 56 | + "tinyauth.apps.foo.response.basicauth.username": "admin", |
| 57 | + "tinyauth.apps.foo.response.basicauth.password": "password", |
| 58 | + "tinyauth.apps.foo.response.basicauth.passwordfile": "/path/to/passwordfile", |
| 59 | + "tinyauth.apps.foo.path.allow": "/public", |
| 60 | + "tinyauth.apps.foo.path.block": "/private", |
| 61 | + } |
| 62 | + |
| 63 | + // Test |
| 64 | + result, err := decoders.DecodeLabels(test) |
| 65 | + |
| 66 | + if err != nil { |
| 67 | + t.Fatalf("Unexpected error: %v", err) |
| 68 | + } |
| 69 | + |
| 70 | + if reflect.DeepEqual(expected, result) == false { |
| 71 | + t.Fatalf("Expected %v but got %v", expected, result) |
| 72 | + } |
| 73 | +} |
0 commit comments