-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbasicAuthenticationAdapter.test.ts
More file actions
76 lines (74 loc) · 2.11 KB
/
Copy pathbasicAuthenticationAdapter.test.ts
File metadata and controls
76 lines (74 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { callHttpInterceptors } from '@apimatic/core';
import { basicAuthenticationProvider } from '../src/basicAuthenticationAdapter';
import { HttpRequest, HttpResponse } from '@apimatic/core-interfaces';
describe('test basic authentication scheme', () => {
const config = {
timeout: 60000,
environment: 'Production',
customUrl: 'https://connect.product.com',
basicAuthUserName: 'maryam',
basicAuthPassword: '12345678',
};
test.each([
[
'should test basic auth with enabled authentication',
true,
{
method: 'GET',
url: 'http://apimatic.hopto.org:3000/test/requestBuilder',
} as HttpRequest,
{
statusCode: 200,
body: 'testBody',
headers: { 'test-header': 'test-value' },
} as HttpResponse,
'maryam',
'12345678',
],
[
'should test basic auth with disabled authentication',
false,
{
method: 'GET',
url: 'http://apimatic.hopto.org:3000/test/requestBuilder',
} as HttpRequest,
{
statusCode: 200,
body: 'testBody',
headers: { 'test-header': 'test-value' },
} as HttpResponse,
undefined,
undefined,
],
])(
'%s',
async (
_: string,
enableAuthentication: boolean,
request: HttpRequest,
response: HttpResponse,
token: string | undefined,
apiKey: string | undefined
) => {
const authenticationProvider = basicAuthenticationProvider(
config.basicAuthUserName,
config.basicAuthPassword
);
const handler = authenticationProvider(enableAuthentication);
const interceptor = [handler];
const client = async (req) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
const context = await executor(request, undefined);
if (token === undefined || apiKey === undefined) {
expect(context.request.auth).toBeUndefined();
} else {
expect(context.request.auth).toEqual({
username: 'maryam',
password: '12345678',
});
}
}
);
});