0
0
Postmantesting~10 mins

Basic authentication in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the Authorization header for Basic authentication in Postman.

Postman
pm.request.headers.add({ key: 'Authorization', value: 'Basic [1]' });
Drag options to blanks, or click blank then click option'
Abtoa('username:password')
Batob('username:password')
C'username:password'
DencodeURI('username:password')
Attempts:
3 left
💡 Hint
Common Mistakes
Using atob() which decodes base64 instead of encoding.
Passing the plain 'username:password' string without encoding.
Using URL encoding instead of base64 encoding.
2fill in blank
medium

Complete the code to extract the username and password from the Authorization header in a Postman test script.

Postman
const encoded = pm.request.headers.get('Authorization').split(' ')[[1]];
Drag options to blanks, or click blank then click option'
A1
B2
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which gives the word 'Basic' instead of the encoded string.
Using index 2 which is out of range.
Using -1 which is not valid in JavaScript split arrays.
3fill in blank
hard

Fix the error in decoding the Basic auth credentials in the Postman test script.

Postman
const decoded = [1](encoded);
Drag options to blanks, or click blank then click option'
AencodeURI
Batob
Cbtoa
DdecodeURI
Attempts:
3 left
💡 Hint
Common Mistakes
Using btoa() which encodes instead of decodes.
Using URI encoding functions which do not handle base64.
Trying to parse the encoded string directly without decoding.
4fill in blank
hard

Fill both blanks to check if the Authorization header uses Basic authentication and extract the encoded credentials.

Postman
if (pm.request.headers.get('Authorization')?.startsWith([1])) {
  const encoded = pm.request.headers.get('Authorization').split(' ')[[2]];
}
Drag options to blanks, or click blank then click option'
A'Basic'
B'Bearer'
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'Bearer' instead of 'Basic'.
Using index 0 which gives the word 'Basic' instead of the encoded string.
Not using optional chaining which can cause errors if header is missing.
5fill in blank
hard

Fill all three blanks to decode Basic auth credentials and split them into username and password.

Postman
const encoded = pm.request.headers.get('Authorization').split(' ')[[1]];
const decoded = [2](encoded);
const [[3], password] = decoded.split(':');
Drag options to blanks, or click blank then click option'
A0
B1
Catob
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which is the word 'Basic'.
Using btoa() instead of atob().
Not splitting the decoded string to get username and password.