@unito/integration-cli 0.57.1 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.eslintrc.d.ts +6 -0
- package/dist/.eslintrc.js +9 -2
- package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/src/index.ts +1 -3
- package/dist/src/commands/activity.d.ts +2 -2
- package/dist/src/commands/activity.js +2 -2
- package/dist/src/commands/dev.d.ts +8 -4
- package/dist/src/commands/dev.js +42 -5
- package/dist/src/commands/encrypt.d.ts +1 -1
- package/dist/src/commands/encrypt.js +1 -1
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +3 -3
- package/dist/src/commands/invite.d.ts +1 -1
- package/dist/src/commands/invite.js +2 -2
- package/dist/src/commands/login.d.ts +1 -1
- package/dist/src/commands/login.js +1 -1
- package/dist/src/commands/oauth2.d.ts +3 -3
- package/dist/src/commands/oauth2.js +19 -14
- package/dist/src/commands/publish.d.ts +2 -2
- package/dist/src/commands/publish.js +12 -12
- package/dist/src/commands/test.js +32 -8
- package/dist/src/commands/upgrade.js +3 -3
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.js +35 -18
- package/dist/src/resources/configuration.js +0 -2
- package/dist/src/resources/credentials.d.ts +3 -0
- package/dist/src/resources/credentials.js +26 -0
- package/dist/src/resources/integrations.d.ts +1 -0
- package/dist/src/resources/integrations.js +37 -2
- package/dist/src/resources/oauth2Helper.d.ts +4 -0
- package/dist/src/resources/oauth2Helper.js +30 -0
- package/dist/src/services/integrationsPlatform.d.ts +1 -0
- package/dist/src/services/integrationsPlatform.js +5 -1
- package/dist/src/services/oauth2Helper.d.ts +78 -3
- package/dist/src/services/oauth2Helper.js +229 -29
- package/dist/test/commands/activity.test.js +12 -9
- package/dist/test/commands/dev.test.js +59 -10
- package/dist/test/commands/encrypt.test.js +6 -7
- package/dist/test/commands/init.test.js +7 -9
- package/dist/test/commands/invite.test.js +11 -11
- package/dist/test/commands/login.test.js +20 -23
- package/dist/test/commands/oauth2.test.js +6 -2
- package/dist/test/commands/publish.test.js +152 -218
- package/dist/test/commands/test.test.js +65 -13
- package/dist/test/commands/upgrade.test.js +4 -6
- package/dist/test/errors.test.js +36 -36
- package/dist/test/helpers/integrations.d.ts +26 -0
- package/dist/test/helpers/integrations.js +25 -0
- package/dist/test/helpers/styles.d.ts +1 -0
- package/dist/test/helpers/styles.js +8 -0
- package/dist/test/oauth2Helper/oauth2Helper.test.js +112 -128
- package/dist/test/resources/configuration.test.js +24 -24
- package/dist/test/resources/decryption.test.js +9 -9
- package/dist/test/resources/globalConfiguration.test.js +4 -4
- package/dist/test/resources/integrations.test.js +37 -0
- package/dist/test/resources/oauth2Helper.test.js +55 -0
- package/dist/test/services/integrationsPlatform.test.js +20 -20
- package/oclif.manifest.json +64 -9
- package/package.json +10 -14
- package/dist/integrationGenerator/errors.d.ts +0 -2
- package/dist/integrationGenerator/errors.js +0 -6
- package/dist/integrationGenerator/index.d.ts +0 -2
- package/dist/integrationGenerator/index.js +0 -5
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.dockerignore +0 -3
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.eslintrc.js +0 -74
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierignore +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierrc +0 -7
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.unito.json +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +0 -38
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/README.md +0 -21
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/index.ts +0 -94
- package/dist/integrationGenerator/integrationBoilerplate/package.json +0 -43
- package/dist/integrationGenerator/integrationBoilerplate/src/logger.ts +0 -55
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +0 -22
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/correlationId.ts +0 -13
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/credentials.ts +0 -38
- package/dist/integrationGenerator/integrationBoilerplate/src/request.ts +0 -59
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/index.ts +0 -11
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/me.ts +0 -15
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/root.ts +0 -12
- package/dist/integrationGenerator/integrationBoilerplate/tsconfig.json +0 -37
- package/dist/integrationGenerator/src/index.d.ts +0 -1
- package/dist/integrationGenerator/src/index.js +0 -5
- package/dist/integrationGenerator/src/resources/index.d.ts +0 -1
- package/dist/integrationGenerator/src/resources/index.js +0 -5
- package/dist/integrationGenerator/src/resources/integration.d.ts +0 -9
- package/dist/integrationGenerator/src/resources/integration.js +0 -60
- package/dist/integrationGenerator/test/resources/integration.test.js +0 -51
- package/dist/src/oauth2Helper/oauth2Helper.d.ts +0 -63
- package/dist/src/oauth2Helper/oauth2Helper.js +0 -235
- package/dist/src/oauth2Helper/types.d.ts +0 -22
- package/dist/src/oauth2Helper/types.js +0 -2
- package/dist/test/mocha.hooks.d.ts +0 -2
- package/dist/test/mocha.hooks.js +0 -37
- package/dist/test/services/oauth2Helper.test.js +0 -85
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.dockerignore +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.eslintrc.js +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.nvmrc +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierignore +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierrc +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.unito.json +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/Dockerfile +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/README.md +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/package.json +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/logger.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/additionalLoggingContext.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/correlationId.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/credentials.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/request.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/index.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/me.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/root.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/tsconfig.json +0 -0
- /package/dist/{integrationGenerator/test/resources/integration.test.d.ts → test/resources/integrations.test.d.ts} +0 -0
- /package/dist/test/{services → resources}/oauth2Helper.test.d.ts +0 -0
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.open = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const express_1 = tslib_1.__importDefault(require("express"));
|
|
6
|
-
const cors_1 = tslib_1.__importDefault(require("cors"));
|
|
7
|
-
const openUrl = tslib_1.__importStar(require("openurl"));
|
|
8
|
-
const configurationTypes_1 = require("../configurationTypes");
|
|
9
|
-
const errors_1 = require("../errors");
|
|
10
|
-
// It allows to stub openUrl library in the test
|
|
11
|
-
exports.open = openUrl;
|
|
12
|
-
class OAuth2Helper {
|
|
13
|
-
server = null;
|
|
14
|
-
clientId;
|
|
15
|
-
clientSecret;
|
|
16
|
-
providerAuthorizationUrl;
|
|
17
|
-
tokenUrl;
|
|
18
|
-
scopes;
|
|
19
|
-
grantType;
|
|
20
|
-
requestContentType;
|
|
21
|
-
responseContentType;
|
|
22
|
-
refreshToken;
|
|
23
|
-
code = '';
|
|
24
|
-
serverUrl = '';
|
|
25
|
-
tokenRequestParameters;
|
|
26
|
-
refreshRequestParameters;
|
|
27
|
-
/**
|
|
28
|
-
* Constructs an instance of OAuthHelper.
|
|
29
|
-
* @param clientId The client ID for your OAuth application.
|
|
30
|
-
* @param clientSecret The client secret for your OAuth application.
|
|
31
|
-
* @param authorizationUrl The URL for the authorization endpoint of the provider.
|
|
32
|
-
* @param scopes The scopes required for the OAuth authorization.
|
|
33
|
-
* @param providerTokenUrl The URL for the token endpoint of the provider.
|
|
34
|
-
*/
|
|
35
|
-
constructor(authorizationInfo) {
|
|
36
|
-
const { clientId, clientSecret, authorizationUrl, scopes, tokenUrl, grantType, requestContentType, responseContentType, refreshToken, refreshRequestParameters, tokenRequestParameters, } = authorizationInfo;
|
|
37
|
-
this.startServer = this.startServer.bind(this);
|
|
38
|
-
this.stopServer = this.stopServer.bind(this);
|
|
39
|
-
this.handleAuthorize = this.handleAuthorize.bind(this);
|
|
40
|
-
this.handleCallback = this.handleCallback.bind(this);
|
|
41
|
-
this.handleToken = this.handleToken.bind(this);
|
|
42
|
-
this.clientId = clientId;
|
|
43
|
-
this.clientSecret = clientSecret;
|
|
44
|
-
this.providerAuthorizationUrl = authorizationUrl;
|
|
45
|
-
this.scopes = scopes.map(scope => scope.name);
|
|
46
|
-
this.tokenUrl = tokenUrl;
|
|
47
|
-
this.grantType = grantType ?? configurationTypes_1.GrantType.AUTHORIZATION_CODE;
|
|
48
|
-
this.requestContentType = requestContentType ?? configurationTypes_1.RequestContentType.URL_ENCODED;
|
|
49
|
-
this.responseContentType = responseContentType ?? configurationTypes_1.RequestContentType.JSON;
|
|
50
|
-
this.refreshToken = refreshToken;
|
|
51
|
-
this.tokenRequestParameters = tokenRequestParameters;
|
|
52
|
-
this.refreshRequestParameters = refreshRequestParameters;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Handles the authorization request and redirects the user to the provider's authorization page.
|
|
56
|
-
* @param req The express Request object.
|
|
57
|
-
* @param res The express Response object.
|
|
58
|
-
*/
|
|
59
|
-
async handleAuthorize(_req, res) {
|
|
60
|
-
if (!this.providerAuthorizationUrl) {
|
|
61
|
-
res.status(422).send({ message: 'providerAuthorizationUrl must be defined in .unito.json' });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const authUrl = new URL(this.providerAuthorizationUrl);
|
|
65
|
-
const params = new URLSearchParams(authUrl.search);
|
|
66
|
-
if (this.clientId) {
|
|
67
|
-
params.set('client_id', this.clientId);
|
|
68
|
-
}
|
|
69
|
-
params.set('redirect_uri', `${this.serverUrl}/credentials/new/oauth2/callback`);
|
|
70
|
-
if (this.scopes) {
|
|
71
|
-
params.set('scope', this.scopes.join(' '));
|
|
72
|
-
}
|
|
73
|
-
params.set('response_type', 'code');
|
|
74
|
-
authUrl.search = params.toString();
|
|
75
|
-
exports.open.open(authUrl.toString());
|
|
76
|
-
res.json();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Handles the callback request from the provider and stores the authorization code.
|
|
80
|
-
* @param req The express Request object.
|
|
81
|
-
* @param res The express Response object.
|
|
82
|
-
*/
|
|
83
|
-
async handleCallback(req, res) {
|
|
84
|
-
const { code } = req.query;
|
|
85
|
-
this.code = code;
|
|
86
|
-
res.json();
|
|
87
|
-
}
|
|
88
|
-
encodeBody(bodyData, contentType) {
|
|
89
|
-
switch (contentType) {
|
|
90
|
-
case configurationTypes_1.RequestContentType.URL_ENCODED:
|
|
91
|
-
return new URLSearchParams(bodyData).toString();
|
|
92
|
-
case configurationTypes_1.RequestContentType.JSON:
|
|
93
|
-
return JSON.stringify(bodyData);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Handles the token request to exchange the authorization code for an access token.
|
|
98
|
-
* @param req The express Request object.
|
|
99
|
-
* @param res The express Response object.
|
|
100
|
-
*/
|
|
101
|
-
async handleToken(_req, res) {
|
|
102
|
-
if (!Object.values(configurationTypes_1.RequestContentType).includes(this.requestContentType)) {
|
|
103
|
-
res.status(400).json({ error: `Request content type not supported: ${this.requestContentType}` });
|
|
104
|
-
}
|
|
105
|
-
const bodyData = {
|
|
106
|
-
code: this.code,
|
|
107
|
-
grant_type: this.grantType,
|
|
108
|
-
redirect_uri: `${this.serverUrl}/credentials/new/oauth2/callback`,
|
|
109
|
-
};
|
|
110
|
-
if (this.clientId) {
|
|
111
|
-
bodyData.client_id = this.clientId;
|
|
112
|
-
}
|
|
113
|
-
if (this.clientSecret) {
|
|
114
|
-
bodyData.client_secret = this.clientSecret;
|
|
115
|
-
}
|
|
116
|
-
const body = this.encodeBody(bodyData, this.requestContentType);
|
|
117
|
-
const fetchOptions = {
|
|
118
|
-
headers: {
|
|
119
|
-
'Content-type': this.requestContentType,
|
|
120
|
-
...(this.tokenRequestParameters?.header ?? {}),
|
|
121
|
-
},
|
|
122
|
-
body,
|
|
123
|
-
method: 'POST',
|
|
124
|
-
};
|
|
125
|
-
try {
|
|
126
|
-
const fetchResult = await fetch(this.tokenUrl, fetchOptions);
|
|
127
|
-
if (fetchResult.status !== 200) {
|
|
128
|
-
res.status(500).json({ error: `Error fetching token: ${await fetchResult.text()}` });
|
|
129
|
-
}
|
|
130
|
-
const response = await fetchResult.json();
|
|
131
|
-
const credentialsInfo = {
|
|
132
|
-
accessToken: response.access_token,
|
|
133
|
-
refreshToken: response.refresh_token,
|
|
134
|
-
};
|
|
135
|
-
res.json(credentialsInfo);
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
res.status(500).json({ error: 'Failed to retrieve access token' });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async updateToken() {
|
|
142
|
-
if (!this.refreshToken) {
|
|
143
|
-
throw new errors_1.NoRefreshTokenError();
|
|
144
|
-
}
|
|
145
|
-
if (!Object.values(configurationTypes_1.RequestContentType).includes(this.requestContentType)) {
|
|
146
|
-
throw new errors_1.InvalidRequestContentTypeError(`Request content type not supported: ${this.requestContentType}`);
|
|
147
|
-
}
|
|
148
|
-
const bodyData = {
|
|
149
|
-
grant_type: 'refresh_token',
|
|
150
|
-
refresh_token: this.refreshToken,
|
|
151
|
-
};
|
|
152
|
-
if (this.clientId) {
|
|
153
|
-
bodyData.client_id = this.clientId;
|
|
154
|
-
}
|
|
155
|
-
if (this.clientSecret) {
|
|
156
|
-
bodyData.client_secret = this.clientSecret;
|
|
157
|
-
}
|
|
158
|
-
const fetchOptions = {
|
|
159
|
-
headers: {
|
|
160
|
-
'Content-type': this.requestContentType,
|
|
161
|
-
...(this.refreshRequestParameters?.header ?? {}),
|
|
162
|
-
},
|
|
163
|
-
body: this.encodeBody(bodyData, this.requestContentType),
|
|
164
|
-
method: 'POST',
|
|
165
|
-
};
|
|
166
|
-
try {
|
|
167
|
-
const fetchResult = await fetch(this.tokenUrl, fetchOptions);
|
|
168
|
-
if (fetchResult.status !== 200) {
|
|
169
|
-
throw new errors_1.FailedToRetrieveAccessTokenError(await fetchResult.text());
|
|
170
|
-
}
|
|
171
|
-
const response = await fetchResult.json();
|
|
172
|
-
const credentialsInfo = {
|
|
173
|
-
accessToken: response.access_token,
|
|
174
|
-
refreshToken: response.refresh_token,
|
|
175
|
-
};
|
|
176
|
-
return credentialsInfo;
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
throw new errors_1.FailedToRetrieveAccessTokenError(JSON.stringify(error));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Starts the Express server for handling OAuth callbacks.
|
|
184
|
-
* @returns The URL of the server.
|
|
185
|
-
*/
|
|
186
|
-
/* istanbul ignore next */
|
|
187
|
-
startServer() {
|
|
188
|
-
const app = (0, express_1.default)();
|
|
189
|
-
const PORT = process.env.OAUTH2_PORT ?? 9002;
|
|
190
|
-
app.use((0, cors_1.default)({ credentials: true, origin: true }));
|
|
191
|
-
app.get('/health', (req, res) => {
|
|
192
|
-
res.send('pong');
|
|
193
|
-
});
|
|
194
|
-
app.get('/credentials/new/oauth2/authorize', this.handleAuthorize);
|
|
195
|
-
app.get('/credentials/new/oauth2/callback', this.handleCallback);
|
|
196
|
-
app.get('/credentials/new/oauth2/token', this.handleToken);
|
|
197
|
-
this.server = app.listen(PORT, () => {
|
|
198
|
-
console.log(`Listening at port ${PORT}`);
|
|
199
|
-
});
|
|
200
|
-
this.serverUrl = `http://localhost:${PORT}`;
|
|
201
|
-
return this.serverUrl;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Stops the Express server.
|
|
205
|
-
*/
|
|
206
|
-
/* istanbul ignore next */
|
|
207
|
-
stopServer() {
|
|
208
|
-
if (this.server) {
|
|
209
|
-
this.server.close(() => {
|
|
210
|
-
console.log('Server has stopped');
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Waits for the authorization code to be set.
|
|
216
|
-
* @returns A promise that resolves when the code is set.
|
|
217
|
-
*/
|
|
218
|
-
/* istanbul ignore next */
|
|
219
|
-
async callbackIsDone() {
|
|
220
|
-
if (this.code) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
return new Promise(resolve => {
|
|
225
|
-
const interval = setInterval(() => {
|
|
226
|
-
if (this.code) {
|
|
227
|
-
clearInterval(interval);
|
|
228
|
-
resolve(true);
|
|
229
|
-
}
|
|
230
|
-
}, 100);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
exports.default = OAuth2Helper;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Oauth2 } from '../configurationTypes';
|
|
2
|
-
export interface Oauth2Credentials {
|
|
3
|
-
clientId: string;
|
|
4
|
-
clientSecret: string;
|
|
5
|
-
}
|
|
6
|
-
export interface AuthorizePayload extends Oauth2Credentials {
|
|
7
|
-
providerAuthorizationUrl: string;
|
|
8
|
-
scopes?: string;
|
|
9
|
-
providerAccessTokenUrl: string;
|
|
10
|
-
}
|
|
11
|
-
export interface CallbackPayload {
|
|
12
|
-
code: string;
|
|
13
|
-
}
|
|
14
|
-
export interface Oauth2Response {
|
|
15
|
-
accessToken: string;
|
|
16
|
-
refreshToken?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface TokenPayload extends Oauth2Credentials {
|
|
19
|
-
providerTokenUrl: string;
|
|
20
|
-
code: string;
|
|
21
|
-
}
|
|
22
|
-
export type Oauth2Payload = Oauth2 & Omit<Oauth2Response, 'accessToken'>;
|
package/dist/test/mocha.hooks.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.mochaHooks = void 0;
|
|
27
|
-
const mochaHooks = () => {
|
|
28
|
-
return {
|
|
29
|
-
async beforeAll() {
|
|
30
|
-
// Allow using `chai-as-promised` in all tests.
|
|
31
|
-
const chai = await Promise.resolve().then(() => __importStar(require('chai')));
|
|
32
|
-
const chaiAsPromised = await Promise.resolve().then(() => __importStar(require('chai-as-promised')));
|
|
33
|
-
chai.use(chaiAsPromised.default);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
exports.mochaHooks = mochaHooks;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const sinon_1 = tslib_1.__importDefault(require("sinon"));
|
|
6
|
-
const oauth2Helper_1 = tslib_1.__importDefault(require("../../src/oauth2Helper/oauth2Helper"));
|
|
7
|
-
const configurationTypes_1 = require("../../src/configurationTypes");
|
|
8
|
-
const oauth2HelperService = tslib_1.__importStar(require("../../src/services/oauth2Helper"));
|
|
9
|
-
const errors_1 = require("../../src/errors");
|
|
10
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
11
|
-
describe('OAuth2Helper', () => {
|
|
12
|
-
let fetchStub;
|
|
13
|
-
const authorizationInfo = {
|
|
14
|
-
clientId: 'your-client-id',
|
|
15
|
-
clientSecret: 'your-client-secret',
|
|
16
|
-
authorizationUrl: 'https://provider.com/oauth/authorize',
|
|
17
|
-
scopes: [{ name: 'scope1' }, { name: 'scope2' }],
|
|
18
|
-
tokenUrl: 'https://provider.com/oauth/token',
|
|
19
|
-
grantType: configurationTypes_1.GrantType.AUTHORIZATION_CODE,
|
|
20
|
-
requestContentType: configurationTypes_1.RequestContentType.URL_ENCODED,
|
|
21
|
-
responseContentType: configurationTypes_1.RequestContentType.JSON,
|
|
22
|
-
};
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
sinon_1.default.stub(oauth2Helper_1.default.prototype, 'startServer').returns('http://localhost:5050');
|
|
25
|
-
sinon_1.default.stub(oauth2Helper_1.default.prototype, 'stopServer');
|
|
26
|
-
sinon_1.default.stub(oauth2Helper_1.default.prototype, 'callbackIsDone');
|
|
27
|
-
sinon_1.default.stub(inquirer_1.default, 'prompt');
|
|
28
|
-
});
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
sinon_1.default.restore();
|
|
31
|
-
});
|
|
32
|
-
describe('performOAuth2Flow', () => {
|
|
33
|
-
it('should perform the oauth flow', async () => {
|
|
34
|
-
fetchStub = sinon_1.default
|
|
35
|
-
.stub()
|
|
36
|
-
.onFirstCall()
|
|
37
|
-
.resolves({ status: 200 })
|
|
38
|
-
.onSecondCall()
|
|
39
|
-
.resolves({ status: 200 })
|
|
40
|
-
.onThirdCall()
|
|
41
|
-
.resolves({
|
|
42
|
-
status: 200,
|
|
43
|
-
json: () => {
|
|
44
|
-
return { accessToken: 'token', refresToken: 'refreshToken' };
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
sinon_1.default.replace(global, 'fetch', fetchStub);
|
|
48
|
-
await oauth2HelperService.performOAuth2Flow(authorizationInfo);
|
|
49
|
-
(0, chai_1.expect)(fetchStub.getCall(0).args.at(0)).to.eq('http://localhost:5050/health');
|
|
50
|
-
(0, chai_1.expect)(fetchStub.getCall(1).args.at(0)).to.eq('http://localhost:5050/credentials/new/oauth2/authorize');
|
|
51
|
-
(0, chai_1.expect)(fetchStub.getCall(2).args.at(0)).to.eq('http://localhost:5050/credentials/new/oauth2/token');
|
|
52
|
-
});
|
|
53
|
-
it('raises a FailedToRetrieveAccessTokenError', async () => {
|
|
54
|
-
fetchStub = sinon_1.default
|
|
55
|
-
.stub()
|
|
56
|
-
.onFirstCall()
|
|
57
|
-
.resolves({ status: 200 })
|
|
58
|
-
.onSecondCall()
|
|
59
|
-
.resolves({ status: 200 })
|
|
60
|
-
.onThirdCall()
|
|
61
|
-
.resolves({ status: 500, text: () => 'error' });
|
|
62
|
-
sinon_1.default.replace(global, 'fetch', fetchStub);
|
|
63
|
-
const response = oauth2HelperService.performOAuth2Flow(authorizationInfo);
|
|
64
|
-
await (0, chai_1.expect)(response).to.be.rejectedWith(errors_1.FailedToRetrieveAccessTokenError);
|
|
65
|
-
});
|
|
66
|
-
it('raises a FailedToRetrieveAccessTokenError when the accessToken is not returned', async () => {
|
|
67
|
-
fetchStub = sinon_1.default
|
|
68
|
-
.stub()
|
|
69
|
-
.onFirstCall()
|
|
70
|
-
.resolves({ status: 200 })
|
|
71
|
-
.onSecondCall()
|
|
72
|
-
.resolves({ status: 200 })
|
|
73
|
-
.onThirdCall()
|
|
74
|
-
.resolves({
|
|
75
|
-
status: 200,
|
|
76
|
-
json: () => {
|
|
77
|
-
return {};
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
sinon_1.default.replace(global, 'fetch', fetchStub);
|
|
81
|
-
const response = oauth2HelperService.performOAuth2Flow(authorizationInfo);
|
|
82
|
-
await (0, chai_1.expect)(response).to.be.rejectedWith(errors_1.FailedToRetrieveAccessTokenError);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|