1
- /* global ipfs, webuiUrl, page, describe, it, expect, beforeAll */
1
+ /* global ipfs, webuiUrl, page, describe, it, expect, beforeAll, waitForText */
2
2
3
3
const { createController } = require ( 'ipfsd-ctl' )
4
4
const getPort = require ( 'get-port' )
@@ -105,11 +105,11 @@ const switchIpfsApiEndpointViaLocalStorage = async (endpoint) => {
105
105
}
106
106
107
107
const switchIpfsApiEndpointViaSettings = async ( endpoint ) => {
108
- await expect ( page ) . toClick ( 'a[href="#/settings"]' )
108
+ await page . click ( 'a[href="#/settings"]' )
109
109
const selector = 'input[id="api-address"]'
110
- await page . waitForSelector ( selector , { visible : true } )
111
- await expect ( page ) . toFill ( selector , endpoint )
112
- await page . type ( selector , '\n ' )
110
+ await expect ( page ) . toHaveSelector ( selector )
111
+ await page . fill ( selector , endpoint )
112
+ await page . press ( selector , 'Enter ' )
113
113
await waitForIpfsApiEndpoint ( endpoint )
114
114
}
115
115
@@ -118,7 +118,8 @@ const waitForIpfsApiEndpoint = async (endpoint) => {
118
118
try {
119
119
// unwrap port if JSON config is passed
120
120
const json = JSON . parse ( endpoint )
121
- endpoint = json . port || endpoint
121
+ const uri = new URL ( json . url )
122
+ endpoint = uri . port || endpoint
122
123
} catch ( _ ) { }
123
124
try {
124
125
// unwrap port if inlined basic auth was passed
@@ -128,10 +129,11 @@ const waitForIpfsApiEndpoint = async (endpoint) => {
128
129
endpoint = uri . port || endpoint
129
130
}
130
131
} catch ( _ ) { }
131
- await page . waitForFunction ( `localStorage.getItem('ipfsApi') && localStorage.getItem('ipfsApi').includes('${ endpoint } ')` )
132
+ // await page.waitForFunction(`localStorage.getItem('ipfsApi') && localStorage.getItem('ipfsApi').includes('${endpoint}')`)
133
+ await page . waitForFunction ( endpoint => window . localStorage . getItem ( 'ipfsApi' ) && window . localStorage . getItem ( 'ipfsApi' ) . includes ( endpoint ) , endpoint )
132
134
return
133
135
}
134
- await page . waitForFunction ( ' localStorage.getItem(\ 'ipfsApi\ ') === null' )
136
+ await page . waitForFunction ( ( ) => window . localStorage . getItem ( 'ipfsApi' ) === null )
135
137
}
136
138
137
139
const basicAuthConnectionConfirmation = async ( user , password , proxyPort ) => {
@@ -140,6 +142,7 @@ const basicAuthConnectionConfirmation = async (user, password, proxyPort) => {
140
142
await expectHttpApiAddressOnStatusPage ( 'Custom JSON configuration' )
141
143
// confirm webui is actually connected to expected node :^)
142
144
await expectPeerIdOnStatusPage ( ipfsd . api )
145
+
143
146
// (2) go to Settings and confirm API string includes expected JSON config
144
147
const apiOptions = JSON . stringify ( {
145
148
url : `http://127.0.0.1:${ proxyPort } /` ,
@@ -152,28 +155,31 @@ const basicAuthConnectionConfirmation = async (user, password, proxyPort) => {
152
155
153
156
const expectPeerIdOnStatusPage = async ( api ) => {
154
157
const { id } = await api . id ( )
155
- await expect ( page ) . toMatch ( id )
158
+ await waitForText ( id )
156
159
}
157
160
158
161
const expectHttpApiAddressOnStatusPage = async ( value ) => {
159
- await expect ( page ) . toClick ( 'a[href="#/"]' )
162
+ await page . waitForSelector ( 'a[href="#/"]' )
163
+ await page . click ( 'a[href="#/"]' )
160
164
await page . reload ( ) // instant addr update for faster CI
161
- await page . waitForSelector ( 'summary' , { visible : true } )
162
- await expect ( page ) . toClick ( 'summary' , { text : 'Advanced' } )
163
- const apiAddressOnStatus = await page . waitForSelector ( 'div[id="http-api-address"]' , { visible : true } )
164
- await expect ( apiAddressOnStatus ) . toMatch ( String ( value ) )
165
+ await page . waitForSelector ( 'summary' , { state : 'visible' } )
166
+ await page . click ( 'summary' )
167
+ await page . waitForSelector ( 'div[id="http-api-address"]' , { state : 'visible' } )
168
+ await waitForText ( String ( value ) )
165
169
}
166
170
167
171
const expectHttpApiAddressOnSettingsPage = async ( value ) => {
168
- await expect ( page ) . toClick ( 'a[href="#/settings"]' )
169
- await page . waitForSelector ( 'input[id="api-address"]' , { visible : true } )
172
+ await expect ( page ) . toHaveSelector ( 'a[href="#/settings"]' )
173
+ await page . click ( 'a[href="#/settings"]' )
174
+ await page . waitForSelector ( 'input[id="api-address"]' , { state : 'visible' } )
170
175
const apiAddrInput = await page . $ ( '#api-address' )
171
176
const apiAddrValue = await page . evaluate ( x => x . value , apiAddrInput )
172
177
// if API address is defined as JSON, match objects
173
178
try {
174
179
const json = JSON . parse ( apiAddrValue )
175
180
const expectedJson = JSON . parse ( value )
176
- return await expect ( json ) . toMatchObject ( expectedJson )
181
+ await expect ( json ) . toMatchObject ( expectedJson )
182
+ return
177
183
} catch ( _ ) { }
178
184
// else, match strings (Multiaddr or URL)
179
185
await expect ( apiAddrValue ) . toMatch ( String ( value ) )
@@ -221,8 +227,12 @@ describe('API @ URL', () => {
221
227
} )
222
228
223
229
describe ( 'API with CORS and Basic Auth' , ( ) => {
230
+ afterEach ( async ( ) => {
231
+ await switchIpfsApiEndpointViaLocalStorage ( null )
232
+ } )
233
+
224
234
it ( 'should work when localStorage[ipfsApi] is set to URL with inlined Basic Auth credentials' , async ( ) => {
225
- await switchIpfsApiEndpointViaLocalStorage ( `http://${ user } :${ password } @127.0.0.1:${ proxyPort } ` )
235
+ await switchIpfsApiEndpointViaLocalStorage ( `http://${ user } :${ password } @127.0.0.1:${ proxyPort } / ` )
226
236
await basicAuthConnectionConfirmation ( user , password , proxyPort )
227
237
} )
228
238
@@ -238,7 +248,7 @@ describe('API with CORS and Basic Auth', () => {
238
248
} )
239
249
240
250
it ( 'should work when URL with inlined credentials are entered at the Settings page' , async ( ) => {
241
- const basicAuthApiAddr = `http://${ user } :${ password } @127.0.0.1:${ proxyPort } `
251
+ const basicAuthApiAddr = `http://${ user } :${ password } @127.0.0.1:${ proxyPort } / `
242
252
await switchIpfsApiEndpointViaSettings ( basicAuthApiAddr )
243
253
await basicAuthConnectionConfirmation ( user , password , proxyPort )
244
254
} )
0 commit comments