-
Notifications
You must be signed in to change notification settings - Fork 14
/
authlib_injector_test.go
71 lines (56 loc) · 2.17 KB
/
authlib_injector_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"testing"
)
const FALLBACK_SKIN_DOMAIN_A = "a.example.com"
const FALLBACK_SKIN_DOMAIN_B = "b.example.com"
func TestAuthlibInjector(t *testing.T) {
// Just check that AuthlibInjectorRoot works.
// authlib-injector also expects a X-Authlib-Injector-API-Location header
// on the authserver and sessionserver routes that it uses; those are
// tested in auth_test.go and session_test.go.
{
ts := &TestSuite{}
config := testConfig()
ts.Setup(config)
defer ts.Teardown()
ts.CreateTestUser(ts.Server, TEST_USERNAME)
t.Run("Test /authlib-injector", ts.testAuthlibInjectorRoot)
}
{
ts := &TestSuite{}
auxConfig := testConfig()
auxConfig.Domain = "anotherdomain.example.com"
ts.SetupAux(auxConfig)
config := testConfig()
fallback := ts.ToFallbackAPIServer(ts.AuxApp, "Aux")
fallback.SkinDomains = []string{FALLBACK_SKIN_DOMAIN_A, FALLBACK_SKIN_DOMAIN_B}
config.FallbackAPIServers = []FallbackAPIServer{fallback}
ts.Setup(config)
defer ts.Teardown()
t.Run("Test /authlib-injector, fallback API server", ts.testAuthlibInjectorRootFallback)
}
}
func (ts *TestSuite) testAuthlibInjectorRoot(t *testing.T) {
rec := ts.Get(t, ts.Server, "/authlib-injector", nil, nil)
ts.CheckAuthlibInjectorHeader(t, ts.App, rec)
assert.Equal(t, http.StatusOK, rec.Code)
var response authlibInjectorResponse
assert.Nil(t, json.NewDecoder(rec.Body).Decode(&response))
// Just check the important stuff here
assert.Equal(t, ts.App.FrontEndURL, response.Meta.Links.Homepage)
assert.Equal(t, Unwrap(url.JoinPath(ts.App.FrontEndURL, "web/registration")), response.Meta.Links.Register)
assert.Equal(t, []string{ts.App.Config.Domain}, response.SkinDomains)
}
func (ts *TestSuite) testAuthlibInjectorRootFallback(t *testing.T) {
rec := ts.Get(t, ts.Server, "/authlib-injector", nil, nil)
ts.CheckAuthlibInjectorHeader(t, ts.App, rec)
assert.Equal(t, http.StatusOK, rec.Code)
var response authlibInjectorResponse
assert.Nil(t, json.NewDecoder(rec.Body).Decode(&response))
assert.Equal(t, []string{ts.App.Config.Domain, FALLBACK_SKIN_DOMAIN_A, FALLBACK_SKIN_DOMAIN_B}, response.SkinDomains)
}