fix(fetch): basic authentication without realm (#10979)
This commit is contained in:
		
							parent
							
								
									921aa02ce4
								
							
						
					
					
						commit
						707befd6f7
					
				|  | @ -313,7 +313,7 @@ export abstract class APIRequestContext extends SdkObject { | |||
|         if (response.statusCode === 401 && !options.headers!['authorization']) { | ||||
|           const auth = response.headers['www-authenticate']; | ||||
|           const credentials = this._defaultOptions().httpCredentials; | ||||
|           if (auth?.trim().startsWith('Basic ') && credentials) { | ||||
|           if (auth?.trim().startsWith('Basic') && credentials) { | ||||
|             const { username, password } = credentials; | ||||
|             const encoded = Buffer.from(`${username || ''}:${password || ''}`).toString('base64'); | ||||
|             options.headers!['authorization'] = `Basic ${encoded}`; | ||||
|  |  | |||
|  | @ -115,6 +115,24 @@ it('should return error with wrong credentials', async ({ playwright, server }) | |||
|   expect(response.status()).toBe(401); | ||||
| }); | ||||
| 
 | ||||
| it('should support WWW-Authenticate: Basic', async ({ playwright, server }) => { | ||||
|   let credentials; | ||||
|   server.setRoute('/empty.html', (req, res) => { | ||||
|     if (!req.headers.authorization) { | ||||
|       res.writeHead(401, { 'WWW-Authenticate': 'Basic' }); | ||||
|       res.end('HTTP Error 401 Unauthorized: Access is denied'); | ||||
|       return; | ||||
|     } | ||||
|     credentials = Buffer.from((req.headers.authorization).split(' ')[1] || '', 'base64').toString(); | ||||
|     res.writeHead(200, { 'content-type': 'text/plain' }); | ||||
|     res.end(); | ||||
|   }); | ||||
|   const request = await playwright.request.newContext({ httpCredentials: { username: 'user', password: 'pass' } }); | ||||
|   const response = await request.get(server.EMPTY_PAGE); | ||||
|   expect(response.status()).toBe(200); | ||||
|   expect(credentials).toBe('user:pass'); | ||||
| }); | ||||
| 
 | ||||
| it('should use socks proxy', async ({ playwright, server, socksPort }) => { | ||||
|   const request = await playwright.request.newContext({ proxy: { | ||||
|     server: `socks5://localhost:${socksPort}`, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue