@@ -4,15 +4,11 @@ import {
44 getResource ,
55 isUrlOnRealm ,
66 parseProtocol ,
7- fixRealmUrl ,
8- autocompleteRealmPieces ,
9- autocompleteRealm ,
107 isUrlAbsolute ,
118 isUrlRelative ,
129 isUrlPathAbsolute ,
1310} from '../url' ;
1411import type { Auth } from '../../types' ;
15- import type { AutocompletionDefaults } from '../url' ;
1612
1713const urlClassifierCases = {
1814 // These data are mostly a selection from this resource:
@@ -161,155 +157,3 @@ describe('parseProtocol', () => {
161157 expect ( parseProtocol ( '\xA0http://example.org' ) ) . toEqual ( [ 'http://' , 'example.org' ] ) ;
162158 } ) ;
163159} ) ;
164-
165- describe ( 'fixRealmUrl' , ( ) => {
166- test ( 'undefined input results in empty string' , ( ) => {
167- expect ( fixRealmUrl ( ) ) . toEqual ( '' ) ;
168- } ) ;
169-
170- test ( 'empty url input results in empty string' , ( ) => {
171- expect ( fixRealmUrl ( '' ) ) . toEqual ( '' ) ;
172- } ) ;
173-
174- test ( 'when a realm url is missing a protocol, prepend https' , ( ) => {
175- expect ( fixRealmUrl ( 'example.com' ) ) . toEqual ( 'https://example.com' ) ;
176- } ) ;
177-
178- test ( 'when a realm url has a trailing "/" remove it' , ( ) => {
179- expect ( fixRealmUrl ( 'https://example.com/' ) ) . toEqual ( 'https://example.com' ) ;
180- } ) ;
181-
182- test ( 'when a realm url has two trailing "/" remove them' , ( ) => {
183- expect ( fixRealmUrl ( 'https://example.com//' ) ) . toEqual ( 'https://example.com' ) ;
184- } ) ;
185-
186- test ( 'when input url is correct, do not change it' , ( ) => {
187- expect ( fixRealmUrl ( 'https://example.com' ) ) . toEqual ( 'https://example.com' ) ;
188- } ) ;
189-
190- test ( 'remove white-space around input' , ( ) => {
191- expect ( fixRealmUrl ( ' https://example.com/ ' ) ) . toEqual ( 'https://example.com' ) ;
192- } ) ;
193-
194- test ( 'remove white-space inside input' , ( ) => {
195- const result = fixRealmUrl ( 'https://subdomain .example. com/ ' ) ;
196- expect ( result ) . toEqual ( 'https://subdomain.example.com' ) ;
197- } ) ;
198- } ) ;
199-
200- describe ( 'autocompleteRealmPieces' , ( ) => {
201- const exampleData : AutocompletionDefaults = {
202- protocol : 'http://' ,
203- domain : 'example.com' ,
204- } ;
205-
206- test ( 'the empty string yields reasonable values' , ( ) => {
207- const [ head , , tail ] = autocompleteRealmPieces ( '' , exampleData ) ;
208- expect ( head ) . toEqual ( 'http://' ) ;
209- expect ( tail ) . toEqual ( '.example.com' ) ;
210- } ) ;
211-
212- /* Test that input value is unchanged.
213-
214- Future versions of `autocompleteRealmPieces` may alter certain inputs --
215- for example, by trimming spaces, standardizing to lowercase, or escaping
216- via punycode -- but the particular values tested here should all remain
217- unaltered.
218- */
219- const doSimpleCompletion = ( input : string , data ? : AutocompletionDefaults ) => {
220- const [ head , output , tail ] = autocompleteRealmPieces ( input , data ?? exampleData ) ;
221- expect ( input ) . toEqual ( output ) ;
222- return [ head , tail ] ;
223- } ;
224-
225- test ( 'a plain word is fully autocompleted' , ( ) => {
226- const [ head , tail ] = doSimpleCompletion ( 'host-name' ) ;
227- expect ( head ) . toEqual ( 'http://' ) ;
228- expect ( tail ) . toEqual ( '.example.com' ) ;
229- } ) ;
230-
231- test ( 'an explicit `http` is recognized' , ( ) => {
232- const [ head , tail ] = doSimpleCompletion ( 'http://host-name' ) ;
233- expect ( head ) . toBeFalsy ( ) ;
234- expect ( tail ) . toEqual ( '.example.com' ) ;
235- } ) ;
236-
237- test ( 'an explicit `https` is recognized' , ( ) => {
238- const [ head , tail ] = doSimpleCompletion ( 'https://host-name' ) ;
239- expect ( head ) . toBeFalsy ( ) ;
240- expect ( tail ) . toEqual ( '.example.com' ) ;
241- } ) ;
242-
243- test ( 'an explicit IPv4 is recognized' , ( ) => {
244- const [ head , tail ] = doSimpleCompletion ( '23.6.64.128' ) ;
245- expect ( head ) . toBeTruthy ( ) ;
246- expect ( tail ) . toBeFalsy ( ) ;
247- } ) ;
248-
249- test ( 'an explicit IPv6 is recognized' , ( ) => {
250- const [ head , tail ] = doSimpleCompletion ( '[2a02:26f0:12f:293:0:0:0:255e]' ) ;
251- expect ( head ) . toBeTruthy ( ) ;
252- expect ( tail ) . toBeFalsy ( ) ;
253- } ) ;
254-
255- test ( 'localhost with an explicit port is recognized' , ( ) => {
256- const [ head , tail ] = doSimpleCompletion ( 'localhost:9991' ) ;
257- expect ( head ) . toBeTruthy ( ) ;
258- expect ( tail ) . toBeFalsy ( ) ;
259- } ) ;
260-
261- test ( 'full host name is recognized' , ( ) => {
262- const [ head , tail ] = doSimpleCompletion ( 'my-server.example.com' ) ;
263- expect ( head ) . toBeTruthy ( ) ;
264- expect ( tail ) . toBeFalsy ( ) ;
265- } ) ;
266-
267- test ( 'full host and protocol are recognized' , ( ) => {
268- const [ head , tail ] = doSimpleCompletion ( 'http://my-server.com' ) ;
269- expect ( head ) . toBeFalsy ( ) ;
270- expect ( tail ) . toBeFalsy ( ) ;
271- } ) ;
272-
273- test ( 'fully explicit localhost is recognized' , ( ) => {
274- const [ head , tail ] = doSimpleCompletion ( 'http://localhost:9991' ) ;
275- expect ( head ) . toBeFalsy ( ) ;
276- expect ( tail ) . toBeFalsy ( ) ;
277- } ) ;
278- } ) ;
279-
280- describe ( 'autocompleteRealm' , ( ) => {
281- const zulipData : AutocompletionDefaults = {
282- protocol : 'https://' ,
283- domain : 'zulipchat.com' ,
284- } ;
285-
286- test ( 'when no value is entered return empty string' , ( ) => {
287- const result = autocompleteRealm ( '' , zulipData ) ;
288- expect ( result ) . toEqual ( '' ) ;
289- } ) ;
290-
291- test ( 'when a protocol is provided, use it' , ( ) => {
292- const result = autocompleteRealm ( 'http://example' , zulipData ) ;
293- expect ( result ) . toEqual ( 'http://example.zulipchat.com' ) ;
294- } ) ;
295-
296- test ( 'do not use any other protocol than http and https' , ( ) => {
297- const result = autocompleteRealm ( 'ftp://example' , zulipData ) ;
298- expect ( result ) . toStartWith ( 'https://ftp://' ) ;
299- } ) ;
300-
301- test ( 'if the hostname contains a dot, consider it complete' , ( ) => {
302- const result = autocompleteRealm ( 'mydomain.org' , zulipData ) ;
303- expect ( result ) . toEqual ( 'https://mydomain.org' ) ;
304- } ) ;
305-
306- test ( 'if the hostname contains multiple dots, consider it complete' , ( ) => {
307- const result = autocompleteRealm ( 'subdomain.mydomain.org' , zulipData ) ;
308- expect ( result ) . toEqual ( 'https://subdomain.mydomain.org' ) ;
309- } ) ;
310-
311- test ( 'if the hostname contains a colon, consider it complete' , ( ) => {
312- const result = autocompleteRealm ( 'localhost:9991' , zulipData ) ;
313- expect ( result ) . toEqual ( 'https://localhost:9991' ) ;
314- } ) ;
315- } ) ;
0 commit comments