@@ -1221,7 +1221,6 @@ func TestGetSessionReturnsNilForRequestWithNoSessionWithCheckDatabaseTrueAndSess
12211221This test verifies that the SDK calls the well known API properly in the normal flow
12221222
12231223- Initialise the SDK and verify that the well known API was not called
1224- - Wait for cache age to expire
12251224- Create and verify a session
12261225- Verify that the well known API was called to fetch the keys
12271226*/
@@ -1297,14 +1296,12 @@ func TestThatJWKSIsFetchedAsExpected(t *testing.T) {
12971296}
12981297
12991298/**
1300- This test verifies that the variable used to store the pointer to the JWKS result is updated properly when the
1301- cache expired and the keys need to be refetched. Note that here the thing we are actually checking for is that the
1302- GetJWKSResult.JWKS property is updated correctly since that is the pointer
1299+ This test verifies that the cache used to store the pointer to the JWKS result is updated properly when the
1300+ cache expired and the keys need to be refetched.
13031301
13041302- Init
1305- - Call getJWKS to get the functions
1306- - Fetch the keys
1307- - Wait for cache to expire
1303+ - Call getJWKS to get the keys
1304+ - Wait for access token signing key to change
13081305- Fetch the keys again
13091306- Verify that the KIDs inside the pointer have changed
13101307*/
@@ -1618,7 +1615,7 @@ error as long as one of the provided urls return a valid response
16181615func TestThatGetCombinedJWKSDoesNotThrowIfAtleastOneCoreURLIsValid (t * testing.T ) {
16191616 configValue := supertokens.TypeInput {
16201617 Supertokens : & supertokens.ConnectionInfo {
1621- ConnectionURI : "http://localhost:8080;try.supertokens.io;try.supertokens.io :8080;localhost:90" ,
1618+ ConnectionURI : "http://localhost:8080;example.com :8080;localhost:90" ,
16221619 },
16231620 AppInfo : supertokens.AppInfo {
16241621 APIDomain : "api.supertokens.io" ,
@@ -1643,62 +1640,6 @@ func TestThatGetCombinedJWKSDoesNotThrowIfAtleastOneCoreURLIsValid(t *testing.T)
16431640 assert .NotNil (t , combinedJwks )
16441641}
16451642
1646- /**
1647- This function tests the behaviour of the getJWKS (not get combined) function
1648-
1649- - Init with multiple cores
1650- - Call get jwks
1651- - Make sure that the result count is the same as the number of hosts for core instances
1652- - Fetch JWKS from each of the core URLS
1653- - Verify all the responses
1654-
1655- Note in this test we expect only one valid response, all other cores should return errors
1656- */
1657- func TestThatGetJWKSReturnsAResultForEachConnectionUriProvidedAndThatItIsValid (t * testing.T ) {
1658- configValue := supertokens.TypeInput {
1659- Supertokens : & supertokens.ConnectionInfo {
1660- ConnectionURI : "http://localhost:8080;try.supertokens.io:8080;localhost:90" ,
1661- },
1662- AppInfo : supertokens.AppInfo {
1663- APIDomain : "api.supertokens.io" ,
1664- AppName : "SuperTokens" ,
1665- WebsiteDomain : "supertokens.io" ,
1666- },
1667- RecipeList : []supertokens.Recipe {
1668- Init (nil ),
1669- },
1670- }
1671- BeforeEach ()
1672- unittesting .StartUpST ("localhost" , "8080" )
1673- defer AfterEach ()
1674- err := supertokens .Init (configValue )
1675- if err != nil {
1676- t .Error (err .Error ())
1677- }
1678-
1679- hosts := supertokens .QuerierHosts
1680- jwksObjects := getJWKS ()
1681-
1682- assert .Equal (t , len (hosts ), len (jwksObjects ))
1683-
1684- for i , object := range jwksObjects {
1685- currentHost := hosts [i ].Domain .GetAsStringDangerous ()
1686-
1687- assert .True (t , strings .HasPrefix (object .Path , currentHost ))
1688-
1689- jwkResult := object .Fn (object .Path )
1690-
1691- if strings .Contains (currentHost , "localhost:8080" ) {
1692- assert .Nil (t , jwkResult .Error )
1693- assert .NotNil (t , jwkResult .JWKS )
1694- assert .NotEqual (t , len (jwkResult .JWKS .KIDs ()), 0 )
1695- } else {
1696- assert .NotNil (t , jwkResult .Error )
1697- assert .Nil (t , jwkResult .JWKS )
1698- }
1699- }
1700- }
1701-
17021643/**
17031644This test ensures that the SDK's caching logic for fetching JWKs works fine
17041645
@@ -1789,7 +1730,7 @@ This test uses multiple hosts with only the last one being valid to make sure al
17891730func TestThatTheSDKTriesFetchingJWKSForAllCoreHosts (t * testing.T ) {
17901731 configValue := supertokens.TypeInput {
17911732 Supertokens : & supertokens.ConnectionInfo {
1792- ConnectionURI : "try.supertokens.io:8080 ;localhost:90;http://localhost:8080" ,
1733+ ConnectionURI : "example.com ;localhost:90;http://localhost:8080" ,
17931734 },
17941735 AppInfo : supertokens.AppInfo {
17951736 APIDomain : "api.supertokens.io" ,
@@ -1829,7 +1770,7 @@ This test makes sure that the SDK stop fetching JWKS from multiple cores as soon
18291770func TestThatTheSDKFetchesJWKSFromAllCoreHostsUntilAValidResponse (t * testing.T ) {
18301771 configValue := supertokens.TypeInput {
18311772 Supertokens : & supertokens.ConnectionInfo {
1832- ConnectionURI : "try.supertokens.io:8080 ;http://localhost:8080;localhost:90" ,
1773+ ConnectionURI : "example.com ;http://localhost:8080;localhost:90" ,
18331774 },
18341775 AppInfo : supertokens.AppInfo {
18351776 APIDomain : "api.supertokens.io" ,
@@ -1857,87 +1798,10 @@ func TestThatTheSDKFetchesJWKSFromAllCoreHostsUntilAValidResponse(t *testing.T)
18571798 }
18581799
18591800 assert .Equal (t , len (urlsAttemptedForJWKSFetch ), 2 )
1860- assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [0 ], "try.supertokens.io:8080 " ))
1801+ assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [0 ], "example.com " ))
18611802 assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [1 ], "http://localhost:8080" ))
18621803}
18631804
1864- /**
1865- This test makes sure that get combines jwks
1866- 1. Uses all urls to fetch the JWKS until it finds a valid one
1867- 2. Does not try fetching at all if there is a cached value present
1868- 3. Uses all urls after the cache expires
1869-
1870- The context here is that in golang there was a bug where even though the SDK tried fetching multiple times it would
1871- always use the same URL. So this test makes sure that individual hosts were actually used
1872-
1873- - init with multiple cores, last one being valid
1874- - call get combined jwks and verify that all urls were used
1875- - Call get combines JWKs again and make sure no URLs were used
1876- - Wait for cache to expire
1877- - call get combines jwks and make sure all urls were used
1878- */
1879- func TestThatSDKDoesNotFetchJWKSIsAValidCacheExistsButFetchesAfterItExpiresAndItFetchesFromURLSCorrectly (t * testing.T ) {
1880- originalRefreshlimit := JWKRefreshRateLimit
1881- originalCacheAge := JWKCacheMaxAgeInMs
1882-
1883- JWKRefreshRateLimit = 100
1884- JWKCacheMaxAgeInMs = 2000
1885-
1886- configValue := supertokens.TypeInput {
1887- Supertokens : & supertokens.ConnectionInfo {
1888- ConnectionURI : "try.supertokens.io:8080;http://localhost:8080" ,
1889- },
1890- AppInfo : supertokens.AppInfo {
1891- APIDomain : "api.supertokens.io" ,
1892- AppName : "SuperTokens" ,
1893- WebsiteDomain : "supertokens.io" ,
1894- },
1895- RecipeList : []supertokens.Recipe {
1896- Init (nil ),
1897- },
1898- }
1899- BeforeEach ()
1900- unittesting .StartUpST ("localhost" , "8080" )
1901- defer AfterEach ()
1902- err := supertokens .Init (configValue )
1903- if err != nil {
1904- t .Error (err .Error ())
1905- }
1906-
1907- _ , err = GetCombinedJWKS ()
1908-
1909- if err != nil {
1910- t .Error (err .Error ())
1911- }
1912-
1913- assert .Equal (t , len (urlsAttemptedForJWKSFetch ), 2 )
1914- assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [0 ], "try.supertokens.io:8080" ))
1915- assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [1 ], "http://localhost:8080" ))
1916-
1917- _ , err = GetCombinedJWKS ()
1918-
1919- if err != nil {
1920- t .Error (err .Error ())
1921- }
1922-
1923- assert .Equal (t , len (urlsAttemptedForJWKSFetch ), 0 )
1924-
1925- time .Sleep (3 * time .Second )
1926-
1927- _ , err = GetCombinedJWKS ()
1928-
1929- if err != nil {
1930- t .Error (err .Error ())
1931- }
1932-
1933- assert .Equal (t , len (urlsAttemptedForJWKSFetch ), 2 )
1934- assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [0 ], "try.supertokens.io:8080" ))
1935- assert .True (t , strings .Contains (urlsAttemptedForJWKSFetch [1 ], "http://localhost:8080" ))
1936-
1937- JWKRefreshRateLimit = originalRefreshlimit
1938- JWKCacheMaxAgeInMs = originalCacheAge
1939- }
1940-
19411805type MockResponseWriter struct {}
19421806
19431807func (mw MockResponseWriter ) Header () http.Header {
0 commit comments