froth-webdriverio-framework 3.0.57 → 3.0.59
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/commonMethods/Utils.js +6 -1
- package/commonMethods/jwt.js +64 -0
- package/package.json +2 -1
package/commonMethods/Utils.js
CHANGED
|
@@ -38,6 +38,8 @@ let selectDropDownValue = null;
|
|
|
38
38
|
let acceptalert = null;
|
|
39
39
|
let dismissalert = null;
|
|
40
40
|
|
|
41
|
+
let generateJWT=null;
|
|
42
|
+
|
|
41
43
|
if (process.env.LOCATION == 'local') {
|
|
42
44
|
basepath = ".";
|
|
43
45
|
} else {
|
|
@@ -83,6 +85,8 @@ selectDropDownValue = require(basepath + '/dropDown').select4mDropDownValue;
|
|
|
83
85
|
acceptalert = require(basepath + '/alert.js').acceptAlert;
|
|
84
86
|
dismissalert = require(basepath + '/alert.js').dismissAlert;
|
|
85
87
|
|
|
88
|
+
generateJWT = require(basepath + '/jwt').generateJWTToken;
|
|
89
|
+
|
|
86
90
|
//export the variabels
|
|
87
91
|
module.exports = {
|
|
88
92
|
scrollToEnd,
|
|
@@ -114,5 +118,6 @@ module.exports = {
|
|
|
114
118
|
swipeLeft,
|
|
115
119
|
swipeRight,
|
|
116
120
|
swipeDown,
|
|
117
|
-
swipeUp
|
|
121
|
+
swipeUp,
|
|
122
|
+
generateJWT
|
|
118
123
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// JWT generation script adapted from
|
|
2
|
+
// https://gist.github.com/corbanb/db03150abbe899285d6a86cc480f674d
|
|
3
|
+
const CryptoJS = require('crypto-js');
|
|
4
|
+
|
|
5
|
+
var jwtSecret = "PJJP3CB51A29E8B9A70B29AB5FA3FC5FAFEFB34CFD881D629F3C892E9DF9F169AFA3PJPJ"
|
|
6
|
+
|
|
7
|
+
// Set headers for JWT
|
|
8
|
+
var header = {
|
|
9
|
+
'typ': 'JWT',
|
|
10
|
+
'alg': 'HS256'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Prepare timestamp in seconds
|
|
14
|
+
var currentTimestamp = Math.floor(Date.now() / 1000)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function base64urlEncode(source) {
|
|
18
|
+
let encoded = CryptoJS.enc.Base64.stringify(source);
|
|
19
|
+
encoded = encoded.replace(/=+$/, ''); // Remove padding
|
|
20
|
+
encoded = encoded.replace(/\+/g, '-'); // Replace "+" with "-"
|
|
21
|
+
encoded = encoded.replace(/\//g, '_'); // Replace "/" with "_"
|
|
22
|
+
return encoded;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function generateJWTToken(payload) {
|
|
26
|
+
// Encode the header
|
|
27
|
+
const stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
|
|
28
|
+
const encodedHeader = base64urlEncode(stringifiedHeader);
|
|
29
|
+
|
|
30
|
+
// Encode the payload
|
|
31
|
+
const stringifiedPayload = CryptoJS.enc.Utf8.parse(JSON.stringify(payload));
|
|
32
|
+
const encodedPayload = base64urlEncode(stringifiedPayload);
|
|
33
|
+
|
|
34
|
+
// Combine the header and payload
|
|
35
|
+
const token = `${encodedHeader}.${encodedPayload}`;
|
|
36
|
+
|
|
37
|
+
// Sign the token
|
|
38
|
+
const signature = CryptoJS.HmacSHA256(token, jwtSecret);
|
|
39
|
+
const encodedSignature = base64urlEncode(signature);
|
|
40
|
+
|
|
41
|
+
// Return the full token
|
|
42
|
+
return `${token}.${encodedSignature}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//const jwt = generateJWT();
|
|
46
|
+
//pm.environment.set('jwt_signed', signedToken)
|
|
47
|
+
//console.log('Signed and encoded JWT', jwt)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// function main() {
|
|
51
|
+
// // JWT Payload
|
|
52
|
+
// const payload = {
|
|
53
|
+
// iss: "YTLC_TEST_AUTOMATION_APP",
|
|
54
|
+
// iat: currentTimestamp, // Issued at
|
|
55
|
+
// exp: currentTimestamp + 200, // Expiry time: 30 seconds from issuance
|
|
56
|
+
// user_agent: {
|
|
57
|
+
// id: "janga.reddy@ytl.com"
|
|
58
|
+
// }
|
|
59
|
+
// };
|
|
60
|
+
|
|
61
|
+
// console.log('JWT signed token:', generateJWT(payload));
|
|
62
|
+
// }
|
|
63
|
+
// main()
|
|
64
|
+
module.exports = { generateJWTToken}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.59",
|
|
4
4
|
"readme": "WebdriverIO Integration",
|
|
5
5
|
"description": "WebdriverIO and BrowserStack App Automate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"browserstack-local": "^1.5.5",
|
|
39
39
|
"chai": "^5.1.1",
|
|
40
40
|
"crypto": "^1.0.1",
|
|
41
|
+
"crypto-js": "^4.2.0",
|
|
41
42
|
"deepmerge": "^4.3.1",
|
|
42
43
|
"form-data": "^4.0.0",
|
|
43
44
|
"mysql2": "^3.10.2",
|