1- import { normalizeInstanceUrl } from './gitlab-service' ;
1+ import { instanceUrlChanged , normalizeInstanceUrl } from './gitlab-service' ;
22
33describe ( 'normalizeInstanceUrl' , ( ) => {
44 it ( 'treats undefined as gitlab.com' , ( ) => {
@@ -24,8 +24,10 @@ describe('normalizeInstanceUrl', () => {
2424 expect ( normalizeInstanceUrl ( 'https://gitlab.com' ) ) . toBe ( 'https://gitlab.com' ) ;
2525 } ) ;
2626
27- it ( 'preserves self-hosted URLs' , ( ) => {
28- expect ( normalizeInstanceUrl ( 'http://selfhosted.test:3123' ) ) . toBe ( 'http://selfhosted.test:3123' ) ;
27+ it ( 'preserves https self-hosted URLs' , ( ) => {
28+ expect ( normalizeInstanceUrl ( 'https://selfhosted.test:3123' ) ) . toBe (
29+ 'https://selfhosted.test:3123'
30+ ) ;
2931 } ) ;
3032
3133 it ( 'preserves self-hosted base paths' , ( ) => {
@@ -34,6 +36,10 @@ describe('normalizeInstanceUrl', () => {
3436 ) ;
3537 } ) ;
3638
39+ it ( 'rejects http self-hosted URLs' , ( ) => {
40+ expect ( ( ) => normalizeInstanceUrl ( 'http://selfhosted.test:3123' ) ) . toThrow ( 'must use https' ) ;
41+ } ) ;
42+
3743 it ( 'rejects unsafe self-hosted URLs' , ( ) => {
3844 expect ( ( ) => normalizeInstanceUrl ( 'http://127.0.0.1:8080' ) ) . toThrow ( 'host is not allowed' ) ;
3945 } ) ;
@@ -44,12 +50,24 @@ describe('normalizeInstanceUrl', () => {
4450
4551 // different instances
4652 expect ( normalizeInstanceUrl ( 'https://gitlab.com' ) ) . not . toBe (
47- normalizeInstanceUrl ( 'http ://selfhosted.test:3123' )
53+ normalizeInstanceUrl ( 'https ://selfhosted.test:3123' )
4854 ) ;
4955
5056 // same self-hosted instance with trailing slash difference
51- expect ( normalizeInstanceUrl ( 'http://selfhosted.test:3123/' ) ) . toBe (
52- normalizeInstanceUrl ( 'http://selfhosted.test:3123' )
57+ expect ( normalizeInstanceUrl ( 'https://selfhosted.test:3123/' ) ) . toBe (
58+ normalizeInstanceUrl ( 'https://selfhosted.test:3123' )
59+ ) ;
60+ } ) ;
61+
62+ it ( 'treats a legacy http URL as changed when reconnecting with https' , ( ) => {
63+ expect ( instanceUrlChanged ( 'http://selfhosted.test:3123' , 'https://selfhosted.test:3123' ) ) . toBe (
64+ true
5365 ) ;
5466 } ) ;
67+
68+ it ( 'still rejects a new http URL when checking for an instance change' , ( ) => {
69+ expect ( ( ) =>
70+ instanceUrlChanged ( 'https://selfhosted.test:3123' , 'http://selfhosted.test:3123' )
71+ ) . toThrow ( 'must use https' ) ;
72+ } ) ;
5573} ) ;
0 commit comments