Testando authScope
This commit is contained in:
parent
5209767d90
commit
1db88d9478
1 changed files with 31 additions and 1 deletions
|
@ -13,7 +13,8 @@ const clientSecret = "testClientSecret";
|
|||
const baseClientParams = { apiUrl, authUrl, clientId, clientSecret };
|
||||
const basicAuth = `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`;
|
||||
const contentTypeApplicationJson = "application/json";
|
||||
const defaultGrantType='{"grant_type":"client_credentials"}';
|
||||
const defaultGrantValue='client_credentials';
|
||||
const defaultGrantType=`{"grant_type":"${defaultGrantValue}"}`;
|
||||
|
||||
describe("lhisp-oauth-client", ()=>{
|
||||
it("Shoud Get Access Token with Standard Config", async ()=>{
|
||||
|
@ -99,6 +100,35 @@ describe("lhisp-oauth-client", ()=>{
|
|||
data: '{"grant_type":"PermissaoCustom"}',
|
||||
}));
|
||||
});
|
||||
|
||||
it("Shoud Get Access Token with Auth Scope", async ()=>{
|
||||
const cli = getOauthClient({
|
||||
...baseClientParams,
|
||||
authScope: 'EscopoCustom',
|
||||
});
|
||||
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}","scope":"EscopoCustom"}`,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
function getOauthClient(opt:LhispOauthClientConstructorParams=baseClientParams){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue