@@ -127,3 +127,73 @@ async def should_allow_access(
127127 assert body ["users" ][0 ]["user" ]["firstName" ] == "User2"
128128 assert body ["users" ][1 ]["user" ]["lastName" ] == "Foo"
129129 assert body ["users" ][1 ]["user" ]["firstName" ] == "User1"
130+
131+
132+ async def test_connection_uri_has_http_prefix_if_localhost (app : TestClient ):
133+ connection_uri = start_st ()
134+ connection_uri_without_protocol = connection_uri .replace ("http://" , "" )
135+
136+ st_args = get_st_init_args (
137+ [
138+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" ),
139+ dashboard .init (api_key = "someKey" ),
140+ ]
141+ )
142+
143+ st_config = st_args .get ("supertokens_config" )
144+ if st_config :
145+ st_config .connection_uri = connection_uri_without_protocol
146+
147+ init (** st_args )
148+
149+ res = app .get (url = "/auth/dashboard" )
150+ assert res .status_code == 200
151+ assert f'window.connectionURI = "{ connection_uri } "' in str (res .text )
152+
153+
154+ async def test_connection_uri_has_https_prefix_if_not_localhost (app : TestClient ):
155+ start_st ()
156+ connection_uri = "https://try.supertokens.com"
157+ connection_uri_without_protocol = connection_uri .replace ("https://" , "" )
158+
159+ st_args = get_st_init_args (
160+ [
161+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" ),
162+ dashboard .init (api_key = "someKey" ),
163+ ]
164+ )
165+
166+ st_config = st_args .get ("supertokens_config" )
167+ if st_config :
168+ st_config .connection_uri = connection_uri_without_protocol
169+
170+ init (** st_args )
171+
172+ res = app .get (url = "/auth/dashboard" )
173+ assert res .status_code == 200
174+ assert f'window.connectionURI = "{ connection_uri } "' in str (res .text )
175+
176+
177+ async def test_that_first_connection_uri_is_selected_among_multiple_uris (
178+ app : TestClient ,
179+ ):
180+ first_connection_uri = start_st ()
181+ second_connection_uri = "https://try.supertokens.com"
182+ multiple_connection_uris = f"{ first_connection_uri } ;{ second_connection_uri } "
183+
184+ st_args = get_st_init_args (
185+ [
186+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" ),
187+ dashboard .init (api_key = "someKey" ),
188+ ]
189+ )
190+
191+ st_config = st_args .get ("supertokens_config" )
192+ if st_config :
193+ st_config .connection_uri = multiple_connection_uris
194+
195+ init (** st_args )
196+
197+ res = app .get (url = "/auth/dashboard" )
198+ assert res .status_code == 200
199+ assert f'window.connectionURI = "{ first_connection_uri } "' in str (res .text )
0 commit comments