Skip to content

Commit

Permalink
fix(webdriver): browser request should use btoa for basic auth, not a…
Browse files Browse the repository at this point in the history
…tob (#7401)
  • Loading branch information
jlipps committed Sep 14, 2021
1 parent 132908c commit e8506b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/webdriver/src/request/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class BrowserRequest extends WebDriverRequest {
}

if (options.username && options.password) {
const encodedAuth = atob(`${options.username}:${options.password}`)
const encodedAuth = btoa(`${options.username}:${options.password}`)
kyOptions.headers = {
...kyOptions.headers,
Authorization: `Basic ${encodedAuth}`
Expand Down
19 changes: 19 additions & 0 deletions packages/webdriver/tests/request-browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @jest-environment jsdom
*/

import logger from '@wdio/logger'
import _ky from 'ky'

Expand Down Expand Up @@ -448,6 +452,21 @@ describe('webdriver request', () => {
)
expect(result.message).toBe('ups')
})

it('should correctly handle username and password options', async () => {
const expectedResponse = { value: { 'element-6066-11e4-a52e-4f735466cecf': 'some-elem-123' } }
const req = new BrowserRequest('POST', path, {})

const opts = Object.assign(
req.defaultOptions,
{ url: { pathname: '/session/foobar-123/element' } },
{ username: 'foo', password: 'bar' },
)
const res = await req['_request'](opts)

expect(res).toEqual(expectedResponse)
expect(ky.mock.calls[0][1].headers.Authorization).toEqual('Basic Zm9vOmJhcg==')
})
})

afterEach(() => {
Expand Down

0 comments on commit e8506b1

Please sign in to comment.