@@ -38,15 +38,15 @@ describe('auth tests', () => {
3838 process . env [ `INPUT_SETTINGS-PATH` ] = altHome ;
3939 await io . rmRF ( altHome ) ; // ensure it doesn't already exist
4040
41- await auth . configAuthentication ( id , username , password ) ;
41+ await auth . configAuthentication ( [ id ] , username , password ) ;
4242
4343 expect ( fs . existsSync ( m2Dir ) ) . toBe ( false ) ;
4444 expect ( fs . existsSync ( settingsFile ) ) . toBe ( false ) ;
4545
4646 expect ( fs . existsSync ( altHome ) ) . toBe ( true ) ;
4747 expect ( fs . existsSync ( altSettingsFile ) ) . toBe ( true ) ;
4848 expect ( fs . readFileSync ( altSettingsFile , 'utf-8' ) ) . toEqual (
49- auth . generate ( id , username , password )
49+ auth . generate ( [ id ] , username , password )
5050 ) ;
5151
5252 delete process . env [ `INPUT_SETTINGS-PATH` ] ;
@@ -58,12 +58,27 @@ describe('auth tests', () => {
5858 const username = 'UNAME' ;
5959 const password = 'TOKEN' ;
6060
61- await auth . configAuthentication ( id , username , password ) ;
61+ await auth . configAuthentication ( [ id ] , username , password ) ;
6262
6363 expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
6464 expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
6565 expect ( fs . readFileSync ( settingsFile , 'utf-8' ) ) . toEqual (
66- auth . generate ( id , username , password )
66+ auth . generate ( [ id ] , username , password )
67+ ) ;
68+ } , 100000 ) ;
69+
70+ it ( 'creates settings.xml with minimal configuration and multiple servers' , async ( ) => {
71+ const id1 = 'packages-1' ;
72+ const id2 = 'packages-2' ;
73+ const username = 'UNAME' ;
74+ const password = 'TOKEN' ;
75+
76+ await auth . configAuthentication ( [ id1 , id2 ] , username , password ) ;
77+
78+ expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
79+ expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
80+ expect ( fs . readFileSync ( settingsFile , 'utf-8' ) ) . toEqual (
81+ auth . generate ( [ id1 , id2 ] , username , password )
6782 ) ;
6883 } , 100000 ) ;
6984
@@ -73,12 +88,33 @@ describe('auth tests', () => {
7388 const password = 'TOKEN' ;
7489 const gpgPassphrase = 'GPG' ;
7590
76- await auth . configAuthentication ( id , username , password , gpgPassphrase ) ;
91+ await auth . configAuthentication ( [ id ] , username , password , gpgPassphrase ) ;
7792
7893 expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
7994 expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
8095 expect ( fs . readFileSync ( settingsFile , 'utf-8' ) ) . toEqual (
81- auth . generate ( id , username , password , gpgPassphrase )
96+ auth . generate ( [ id ] , username , password , gpgPassphrase )
97+ ) ;
98+ } , 100000 ) ;
99+
100+ it ( 'creates settings.xml with additional configuration and multiple servers' , async ( ) => {
101+ const id1 = 'packages-1' ;
102+ const id2 = 'packages-2' ;
103+ const username = 'UNAME' ;
104+ const password = 'TOKEN' ;
105+ const gpgPassphrase = 'GPG' ;
106+
107+ await auth . configAuthentication (
108+ [ id1 , id2 ] ,
109+ username ,
110+ password ,
111+ gpgPassphrase
112+ ) ;
113+
114+ expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
115+ expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
116+ expect ( fs . readFileSync ( settingsFile , 'utf-8' ) ) . toEqual (
117+ auth . generate ( [ id1 , id2 ] , username , password , gpgPassphrase )
82118 ) ;
83119 } , 100000 ) ;
84120
@@ -92,12 +128,12 @@ describe('auth tests', () => {
92128 expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
93129 expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
94130
95- await auth . configAuthentication ( id , username , password ) ;
131+ await auth . configAuthentication ( [ id ] , username , password ) ;
96132
97133 expect ( fs . existsSync ( m2Dir ) ) . toBe ( true ) ;
98134 expect ( fs . existsSync ( settingsFile ) ) . toBe ( true ) ;
99135 expect ( fs . readFileSync ( settingsFile , 'utf-8' ) ) . toEqual (
100- auth . generate ( id , username , password )
136+ auth . generate ( [ id ] , username , password )
101137 ) ;
102138 } , 100000 ) ;
103139
@@ -118,7 +154,35 @@ describe('auth tests', () => {
118154 </servers>
119155</settings>` ;
120156
121- expect ( auth . generate ( id , username , password ) ) . toEqual ( expectedSettings ) ;
157+ expect ( auth . generate ( [ id ] , username , password ) ) . toEqual ( expectedSettings ) ;
158+ } ) ;
159+
160+ it ( 'generates valid settings.xml with minimal configuration and multiple servers' , ( ) => {
161+ const id1 = 'packages-1' ;
162+ const id2 = 'packages-2' ;
163+ const username = 'USER' ;
164+ const password = '&<>"\'\'"><&' ;
165+
166+ const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
167+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
168+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
169+ <servers>
170+ <server>
171+ <id>${ id1 } </id>
172+ <username>\${env.${ username } }</username>
173+ <password>\${env.&<>"''"><&}</password>
174+ </server>
175+ <server>
176+ <id>${ id2 } </id>
177+ <username>\${env.${ username } }</username>
178+ <password>\${env.&<>"''"><&}</password>
179+ </server>
180+ </servers>
181+ </settings>` ;
182+
183+ expect ( auth . generate ( [ id1 , id2 ] , username , password ) ) . toEqual (
184+ expectedSettings
185+ ) ;
122186 } ) ;
123187
124188 it ( 'generates valid settings.xml with additional configuration' , ( ) => {
@@ -143,8 +207,85 @@ describe('auth tests', () => {
143207 </servers>
144208</settings>` ;
145209
146- expect ( auth . generate ( id , username , password , gpgPassphrase ) ) . toEqual (
210+ expect ( auth . generate ( [ id ] , username , password , gpgPassphrase ) ) . toEqual (
147211 expectedSettings
148212 ) ;
149213 } ) ;
214+
215+ it ( 'generates valid settings.xml with additional configuration and multiple servers' , ( ) => {
216+ const id1 = 'packages-1' ;
217+ const id2 = 'packages-2' ;
218+ const username = 'USER' ;
219+ const password = '&<>"\'\'"><&' ;
220+ const gpgPassphrase = 'PASSPHRASE' ;
221+
222+ const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
223+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
224+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
225+ <servers>
226+ <server>
227+ <id>${ id1 } </id>
228+ <username>\${env.${ username } }</username>
229+ <password>\${env.&<>"''"><&}</password>
230+ </server>
231+ <server>
232+ <id>${ id2 } </id>
233+ <username>\${env.${ username } }</username>
234+ <password>\${env.&<>"''"><&}</password>
235+ </server>
236+ <server>
237+ <id>gpg.passphrase</id>
238+ <passphrase>\${env.${ gpgPassphrase } }</passphrase>
239+ </server>
240+ </servers>
241+ </settings>` ;
242+
243+ expect (
244+ auth . generate ( [ id1 , id2 ] , username , password , gpgPassphrase )
245+ ) . toEqual ( expectedSettings ) ;
246+ } ) ;
247+
248+ it ( 'generates valid settings.xml with additional configuration and multiple servers, sorting alphabetically and removing duplicates' , ( ) => {
249+ const id1 = 'packages-1' ;
250+ const id2 = 'packages-2' ;
251+ const id3 = 'packages-3' ;
252+ const username = 'USER' ;
253+ const password = '&<>"\'\'"><&' ;
254+ const gpgPassphrase = 'PASSPHRASE' ;
255+
256+ const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
257+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
258+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
259+ <servers>
260+ <server>
261+ <id>${ id1 } </id>
262+ <username>\${env.${ username } }</username>
263+ <password>\${env.&<>"''"><&}</password>
264+ </server>
265+ <server>
266+ <id>${ id2 } </id>
267+ <username>\${env.${ username } }</username>
268+ <password>\${env.&<>"''"><&}</password>
269+ </server>
270+ <server>
271+ <id>${ id3 } </id>
272+ <username>\${env.${ username } }</username>
273+ <password>\${env.&<>"''"><&}</password>
274+ </server>
275+ <server>
276+ <id>gpg.passphrase</id>
277+ <passphrase>\${env.${ gpgPassphrase } }</passphrase>
278+ </server>
279+ </servers>
280+ </settings>` ;
281+
282+ expect (
283+ auth . generate (
284+ [ id3 , id3 , id1 , id2 , id1 , id2 , id3 ] ,
285+ username ,
286+ password ,
287+ gpgPassphrase
288+ )
289+ ) . toEqual ( expectedSettings ) ;
290+ } ) ;
150291} ) ;
0 commit comments