Testando envio de credenciais no corpo da request
This commit is contained in:
parent
1db88d9478
commit
bb932a781f
1 changed files with 29 additions and 0 deletions
|
@ -129,6 +129,35 @@ describe("lhisp-oauth-client", ()=>{
|
||||||
data: `{"grant_type":"${defaultGrantValue}","scope":"EscopoCustom"}`,
|
data: `{"grant_type":"${defaultGrantValue}","scope":"EscopoCustom"}`,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Shoud Get Access Token with Credentials on Request body", async ()=>{
|
||||||
|
const cli = getOauthClient({
|
||||||
|
...baseClientParams,
|
||||||
|
sendAuthCredentialsOnRequestBody: true,
|
||||||
|
});
|
||||||
|
mockedAxios.request.mockReset();
|
||||||
|
mockedAxios.request.mockResolvedValueOnce({
|
||||||
|
data: mockedAccessToken
|
||||||
|
});
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const accessToken = await cli.getAccessToken();
|
||||||
|
expect(accessToken).toBeDefined();
|
||||||
|
expect(accessToken.token_type).toBe(mockedAccessToken.token_type);
|
||||||
|
expect(accessToken.access_token).toBe(mockedAccessToken.access_token);
|
||||||
|
expect(accessToken.expires_in).toBe(mockedAccessToken.expires_in);
|
||||||
|
expect(accessToken.scope).toBe(mockedAccessToken.scope);
|
||||||
|
expect(accessToken.created_at).toBeGreaterThanOrEqual(now);
|
||||||
|
expect(mockedAxios.request).toBeCalledWith(expect.objectContaining({
|
||||||
|
url: authUrl,
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: basicAuth,
|
||||||
|
'Content-Type': contentTypeApplicationJson,
|
||||||
|
},
|
||||||
|
data: `{"grant_type":"${defaultGrantValue}","client_id":"${clientId}","client_secret":"${clientSecret}"}`,
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getOauthClient(opt:LhispOauthClientConstructorParams=baseClientParams){
|
function getOauthClient(opt:LhispOauthClientConstructorParams=baseClientParams){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue