MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / sendBasicAuth

Function sendBasicAuth

javascript/selenium-webdriver/lib/test/fileserver.js:190–213  ·  view source on GitHub ↗
(request, response)

Source from the content-addressed store, hash-verified

188}
189
190function sendBasicAuth(request, response) {
191 const denyAccess = function () {
192 response.writeHead(401, { 'WWW-Authenticate': 'Basic realm="test"' })
193 response.end('Access denied')
194 }
195
196 const basicAuthRegExp = /^\s*basic\s+([a-z0-9\-._~+/]+)=*\s*$/i
197 const auth = request.headers.authorization
198 const match = basicAuthRegExp.exec(auth || '')
199 if (!match) {
200 denyAccess()
201 return
202 }
203
204 const userNameAndPass = Buffer.from(match[1], 'base64').toString()
205 const parts = userNameAndPass.split(':', 2)
206 if (parts[0] !== 'genie' || parts[1] !== 'bottle') {
207 denyAccess()
208 return
209 }
210
211 response.writeHead(200, { 'content-type': 'text/plain' })
212 response.end('Access granted!')
213}
214
215function sendDelayedResponse(request, response) {
216 var duration = 0

Callers

nothing calls this directly

Calls 5

splitMethod · 0.80
endMethod · 0.80
denyAccessFunction · 0.70
toStringMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected