-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathcmrTokenSpec.js
More file actions
63 lines (55 loc) · 1.88 KB
/
Copy pathcmrTokenSpec.js
File metadata and controls
63 lines (55 loc) · 1.88 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
'use strict';
const { CMR } = require('@cumulus/cmr-client');
const { getEDLToken, revokeEDLToken } = require('@cumulus/cmr-client/EarthdataLogin');
const { loadConfig } = require('../../helpers/testUtils');
describe('When using Earthdata Login Token from CMR', () => {
let username;
let password;
let config;
let cmrObject;
let beforeAllFailed = false;
let tokenToRevoke;
beforeAll(async () => {
try {
config = await loadConfig();
process.env.stackName = config.stackName;
process.env.CMR_ENVIRONMENT = 'UAT';
username = process.env.EARTHDATA_USERNAME;
password = process.env.EARTHDATA_PASSWORD;
cmrObject = CMR.getInstance({
provider: 'provider',
username,
password,
});
} catch (error) {
beforeAllFailed = true;
console.log(error);
}
});
afterAll(async () => {
tokenToRevoke = await cmrObject.getToken();
await revokeEDLToken(username, password, process.env.CMR_ENVIRONMENT, tokenToRevoke);
});
describe('Request for getting an Earthdata Login Token for the user using Earthdata credentials', () => {
it('gets an Earthdata login token, or creates one for the user if they are missing it', async () => {
if (beforeAllFailed) {
fail('beforeAll() failed');
} else {
const token = await getEDLToken(username, password, process.env.CMR_ENVIRONMENT);
expect(token).toBeDefined();
expect(token).toBeInstanceOf(String);
}
});
});
describe('Request for getting the EDL token through the CMR object', () => {
it('gets an Earthdata login token the same way as the EarthdataLogin object', async () => {
if (beforeAllFailed) {
fail('beforeAll() failed');
} else {
const token = await cmrObject.getToken();
expect(token).toBeDefined();
expect(token).toBeInstanceOf(String);
}
});
});
});