Skip to content

Commit e5b6b24

Browse files
committed
adds a few tests
1 parent ac54734 commit e5b6b24

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

recipe/session/config_test.go

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,3 +1345,170 @@ func TestCookieSameSiteWithEC2PublicURL(t *testing.T) {
13451345
assert.Equal(t, cookieSameSiteValue, "lax")
13461346
assert.False(t, recipe.Config.CookieSecure)
13471347
}
1348+
1349+
func TestInitWorksFineIfOriginIsPresent(t *testing.T) {
1350+
configValue := supertokens.TypeInput{
1351+
Supertokens: &supertokens.ConnectionInfo{
1352+
ConnectionURI: "http://localhost:8080",
1353+
},
1354+
AppInfo: supertokens.AppInfo{
1355+
AppName: "SuperTokens",
1356+
APIDomain: "api.supertokens.io",
1357+
Origin: "supertokens.io",
1358+
},
1359+
RecipeList: []supertokens.Recipe{
1360+
Init(nil),
1361+
},
1362+
}
1363+
BeforeEach()
1364+
unittesting.StartUpST("localhost", "8080")
1365+
defer AfterEach()
1366+
err := supertokens.Init(configValue)
1367+
if err != nil {
1368+
t.Error(err.Error())
1369+
}
1370+
singletonInstance, err := supertokens.GetInstanceOrThrowError()
1371+
if err != nil {
1372+
t.Error(err.Error())
1373+
}
1374+
origin, err := singletonInstance.AppInfo.GetOrigin(nil, nil)
1375+
if err != nil {
1376+
t.Error(err.Error())
1377+
}
1378+
assert.Equal(t, "https://supertokens.io", origin.GetAsStringDangerous())
1379+
}
1380+
1381+
func TestWebsiteDomainWorks(t *testing.T) {
1382+
configValue := supertokens.TypeInput{
1383+
Supertokens: &supertokens.ConnectionInfo{
1384+
ConnectionURI: "http://localhost:8080",
1385+
},
1386+
AppInfo: supertokens.AppInfo{
1387+
AppName: "SuperTokens",
1388+
APIDomain: "api.supertokens.io",
1389+
WebsiteDomain: "supertokens.io",
1390+
},
1391+
RecipeList: []supertokens.Recipe{
1392+
Init(nil),
1393+
},
1394+
}
1395+
BeforeEach()
1396+
unittesting.StartUpST("localhost", "8080")
1397+
defer AfterEach()
1398+
err := supertokens.Init(configValue)
1399+
if err != nil {
1400+
t.Error(err.Error())
1401+
}
1402+
singletonInstance, err := supertokens.GetInstanceOrThrowError()
1403+
if err != nil {
1404+
t.Error(err.Error())
1405+
}
1406+
origin, err := singletonInstance.AppInfo.GetOrigin(nil, nil)
1407+
if err != nil {
1408+
t.Error(err.Error())
1409+
}
1410+
assert.Equal(t, "https://supertokens.io", origin.GetAsStringDangerous())
1411+
}
1412+
1413+
func TestOriginFunctionWorks(t *testing.T) {
1414+
configValue := supertokens.TypeInput{
1415+
Supertokens: &supertokens.ConnectionInfo{
1416+
ConnectionURI: "http://localhost:8080",
1417+
},
1418+
AppInfo: supertokens.AppInfo{
1419+
AppName: "SuperTokens",
1420+
APIDomain: "api.supertokens.io",
1421+
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
1422+
return "https://test.io", nil
1423+
},
1424+
},
1425+
RecipeList: []supertokens.Recipe{
1426+
Init(nil),
1427+
},
1428+
}
1429+
BeforeEach()
1430+
unittesting.StartUpST("localhost", "8080")
1431+
defer AfterEach()
1432+
err := supertokens.Init(configValue)
1433+
if err != nil {
1434+
t.Error(err.Error())
1435+
}
1436+
singletonInstance, err := supertokens.GetInstanceOrThrowError()
1437+
if err != nil {
1438+
t.Error(err.Error())
1439+
}
1440+
origin, err := singletonInstance.AppInfo.GetOrigin(nil, nil)
1441+
if err != nil {
1442+
t.Error(err.Error())
1443+
}
1444+
assert.Equal(t, "https://test.io", origin.GetAsStringDangerous())
1445+
}
1446+
1447+
func TestOriginIsUsedOverWebsiteDomain(t *testing.T) {
1448+
configValue := supertokens.TypeInput{
1449+
Supertokens: &supertokens.ConnectionInfo{
1450+
ConnectionURI: "http://localhost:8080",
1451+
},
1452+
AppInfo: supertokens.AppInfo{
1453+
AppName: "SuperTokens",
1454+
APIDomain: "api.supertokens.io",
1455+
Origin: "supertokens.io",
1456+
WebsiteDomain: "shouldnotbeused.com",
1457+
},
1458+
RecipeList: []supertokens.Recipe{
1459+
Init(nil),
1460+
},
1461+
}
1462+
BeforeEach()
1463+
unittesting.StartUpST("localhost", "8080")
1464+
defer AfterEach()
1465+
err := supertokens.Init(configValue)
1466+
if err != nil {
1467+
t.Error(err.Error())
1468+
}
1469+
singletonInstance, err := supertokens.GetInstanceOrThrowError()
1470+
if err != nil {
1471+
t.Error(err.Error())
1472+
}
1473+
origin, err := singletonInstance.AppInfo.GetOrigin(nil, nil)
1474+
if err != nil {
1475+
t.Error(err.Error())
1476+
}
1477+
assert.Equal(t, "https://supertokens.io", origin.GetAsStringDangerous())
1478+
}
1479+
1480+
func TestOriginFunctionIsUsedOverOrigin(t *testing.T) {
1481+
configValue := supertokens.TypeInput{
1482+
Supertokens: &supertokens.ConnectionInfo{
1483+
ConnectionURI: "http://localhost:8080",
1484+
},
1485+
AppInfo: supertokens.AppInfo{
1486+
AppName: "SuperTokens",
1487+
APIDomain: "api.supertokens.io",
1488+
Origin: "supertokens.io",
1489+
WebsiteDomain: "shouldnotbeused.com",
1490+
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
1491+
return "test.io", nil
1492+
},
1493+
},
1494+
RecipeList: []supertokens.Recipe{
1495+
Init(nil),
1496+
},
1497+
}
1498+
BeforeEach()
1499+
unittesting.StartUpST("localhost", "8080")
1500+
defer AfterEach()
1501+
err := supertokens.Init(configValue)
1502+
if err != nil {
1503+
t.Error(err.Error())
1504+
}
1505+
singletonInstance, err := supertokens.GetInstanceOrThrowError()
1506+
if err != nil {
1507+
t.Error(err.Error())
1508+
}
1509+
origin, err := singletonInstance.AppInfo.GetOrigin(nil, nil)
1510+
if err != nil {
1511+
t.Error(err.Error())
1512+
}
1513+
assert.Equal(t, "https://test.io", origin.GetAsStringDangerous())
1514+
}

0 commit comments

Comments
 (0)