Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression testing for keyword replacement #695

Merged
merged 27 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6df590a
Remove the test environment at21 and modernizing the configuration lo…
Ahmed-Ghanam Jan 16, 2025
a168797
Modernizing the logic and improve readability.
Ahmed-Ghanam Jan 16, 2025
ab97d63
Modernizing the logic and simplified the return statements.
Ahmed-Ghanam Jan 16, 2025
dba6a0d
Modernized the logic and improved the readability
Ahmed-Ghanam Jan 16, 2025
f390020
Modernized the logic and readability improved.
Ahmed-Ghanam Jan 16, 2025
bdb5f80
Modernized the logic and readability improved.
Ahmed-Ghanam Jan 16, 2025
aafaed0
Modernized the logic and readability improved.
Ahmed-Ghanam Jan 16, 2025
f3c296a
Remove break lines
Ahmed-Ghanam Jan 16, 2025
86c0652
Add a test data
Ahmed-Ghanam Jan 16, 2025
e0a3ed5
Rename a file
Ahmed-Ghanam Jan 16, 2025
6487ece
Modernized the logic.
Ahmed-Ghanam Jan 16, 2025
d426c70
Improve error handling and code readability.
Ahmed-Ghanam Jan 20, 2025
275416e
Code refactoring
Ahmed-Ghanam Jan 20, 2025
67b06a2
Update the test data
Ahmed-Ghanam Jan 20, 2025
4da5d15
Add a separate object to the recipient if necessary.
Ahmed-Ghanam Jan 20, 2025
a3c9996
Shorten the test data content.
Ahmed-Ghanam Jan 20, 2025
18e6fb4
Code refactoring
Ahmed-Ghanam Jan 20, 2025
f2b7166
Improve documentation
Ahmed-Ghanam Jan 20, 2025
6478daa
Code refactoring
Ahmed-Ghanam Jan 20, 2025
4c05381
Code refactoring
Ahmed-Ghanam Jan 20, 2025
50d98d6
Code refactoring
Ahmed-Ghanam Jan 20, 2025
db8cf93
Add a ref to errorhandler.js
Ahmed-Ghanam Jan 20, 2025
6956b51
Remove a duplicate
Ahmed-Ghanam Jan 20, 2025
0f0446f
Reduce duplicates
Ahmed-Ghanam Jan 20, 2025
89e0235
Remove the conditional statement that checks whether the subscription…
Ahmed-Ghanam Jan 22, 2025
50cbe51
Provide detailed instructions on how to execute each command using va…
Ahmed-Ghanam Jan 23, 2025
4be04c2
Merge branch 'main' into test/689-keyword-regression-tests
Ahmed-Ghanam Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions test/k6/src/api/authentication.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { check } from "k6";
import http from "k6/http";

import {
buildHeaderWithBearer
} from "../apiHelpers.js";
import { platformAuthentication } from "../config.js";
import { buildHeaderWithBearer } from "../apiHelpers.js";
import { stopIterationOnFail } from "../errorhandler.js";


export function exchangeToAltinnToken(token, test) {
var endpoint = platformAuthentication.exchange + "?test=" + test;
var params = buildHeaderWithBearer(token);
const endpoint = `${platformAuthentication.exchange}?test=${test}`;

const params = buildHeaderWithBearer(token);

const res = http.get(endpoint, params);

const success = check(res, {
"// Setup // Authentication towards Altinn 3 Success": (r) => r.status === 200,
});

var res = http.get(endpoint, params);
var success = check(res, {
"// Setup // Authentication towards Altinn 3 Success": (r) =>
r.status === 200,
});

stopIterationOnFail("// Setup // Authentication towards Altinn 3 Failed", success);
stopIterationOnFail("// Setup // Authentication towards Altinn 3 Failed", success);

return res.body;
return res.body;
}
110 changes: 54 additions & 56 deletions test/k6/src/api/maskinporten.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,74 @@
import http from "k6/http";
import { check } from "k6";
import encoding from "k6/encoding";
import http from "k6/http";

import { uuidv4 } from "https://jslib.k6.io/k6-utils/1.4.0/index.js";
import KJUR from "https://unpkg.com/[email protected]/lib/jsrsasign.js";

import { buildHeaderWithContentType} from "../apiHelpers.js";
import * as config from "../config.js";
import { stopIterationOnFail } from "../errorhandler.js";
import { buildHeaderWithContentType } from "../apiHelpers.js";
import { uuidv4 } from "https://jslib.k6.io/k6-utils/1.4.0/index.js";
import KJUR from "https://unpkg.com/[email protected]/lib/jsrsasign.js";

const mpKid = __ENV.mpKid;
const encodedJwk = __ENV.encodedJwk;
const mpClientId = __ENV.mpClientId;
const mpKid = __ENV.mpKid;

export function generateAccessToken(scopes) {
if(!encodedJwk){
stopIterationOnFail("Required environment variable Encoded JWK (encodedJWK) was not provided", false);
}
if (!encodedJwk) {
stopIterationOnFail("Required environment variable Encoded JWK (encodedJWK) was not provided", false);
}

if (!mpClientId) {
stopIterationOnFail("Required environment variable maskinporten client id (mpClientId) was not provided", false);
}

if (!mpKid) {
stopIterationOnFail("Required environment variable maskinporten kid (mpKid) was not provided", false);
}

if(!mpClientId){
stopIterationOnFail("Required environment variable maskinporten client id (mpClientId) was not provided", false);
}
const grant = createJwtGrant(scopes);

if(!mpKid){
stopIterationOnFail("Required environment variable maskinporten kid (mpKid) was not provided", false);
}
const body = {
alg: "RS256",
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: grant,
};

var grant = createJwtGrant(scopes);
const res = http.post(config.maskinporten.token, body, buildHeaderWithContentType("application/x-www-form-urlencoded"));

let body = {
alg: "RS256",
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: grant,
};
const success = check(res, {
"// Setup // Authentication towards Maskinporten Success": (r) => r.status === 200,
});

let res = http.post(config.maskinporten.token, body, buildHeaderWithContentType("application/x-www-form-urlencoded"));
stopIterationOnFail("// Setup // Authentication towards Maskinporten Failed", success);

var success = check(res, {
"// Setup // Authentication towards Maskinporten Success": (r) =>
r.status === 200,
});

stopIterationOnFail("// Setup // Authentication towards Maskinporten Failed", success);
const accessToken = JSON.parse(res.body)['access_token'];

let accessToken = JSON.parse(res.body)['access_token'];
return accessToken;
return accessToken;
}

function createJwtGrant(scopes) {
const header = {
alg: "RS256",
typ: "JWT",
kid: mpKid,
};

var now = Math.floor(Date.now() / 1000);

var payload = {
aud: config.maskinporten.audience,
scope: scopes,
iss: mpClientId,
iat: now,
exp: now + 120,
jti: uuidv4(),
};

var signedJWT = KJUR.jws.JWS.sign(
"RS256",
header,
payload,
JSON.parse(encoding.b64decode(encodedJwk, "std", "s"))
);

return signedJWT;
const header = {
alg: "RS256",
typ: "JWT",
kid: mpKid,
};

const now = Math.floor(Date.now() / 1000);

const payload = {
aud: config.maskinporten.audience,
scope: scopes,
iss: mpClientId,
iat: now,
exp: now + 120,
jti: uuidv4(),
};

const signedJWT = KJUR.jws.JWS.sign(
"RS256",
header,
payload,
JSON.parse(encoding.b64decode(encodedJwk, "std", "s"))
);

return signedJWT;
}
20 changes: 10 additions & 10 deletions test/k6/src/api/notifications/notifications.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import http from "k6/http";

import * as config from "../../config.js";

import * as apiHelpers from "../../apiHelpers.js";

export function getEmailNotifications(orderId, token) {
var endpoint = config.notifications.notifications_email(orderId);
var params = apiHelpers.buildHeaderWithBearer(token);
var response = http.get(endpoint, params);
return response;
const params = apiHelpers.buildHeaderWithBearer(token);

const endpoint = config.notifications.notifications_email(orderId);

return http.get(endpoint, params);
}

export function getSmsNotifications(orderId, token) {
var endpoint = config.notifications.notifications_sms(orderId);
var params = apiHelpers.buildHeaderWithBearer(token);
var response = http.get(endpoint, params);
return response;
const params = apiHelpers.buildHeaderWithBearer(token);

const endpoint = config.notifications.notifications_sms(orderId);

return http.get(endpoint, params);
}
45 changes: 20 additions & 25 deletions test/k6/src/api/notifications/orders.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
import http from "k6/http";

import * as config from "../../config.js";

import * as apiHelpers from "../../apiHelpers.js";

export function postEmailNotificationOrder(serializedOrder, token) {
var endpoint = config.notifications.orders_email;

var params = apiHelpers.buildHeaderWithBearerAndContentType(token);
const endpoint = config.notifications.orders_email;

var response = http.post(endpoint, serializedOrder, params);
const params = apiHelpers.buildHeaderWithBearerAndContentType(token);

return response;
return http.post(endpoint, serializedOrder, params);
}

export function postSmsNotificationOrder(serializedOrder, token) {
var endpoint = config.notifications.orders_sms;
const endpoint = config.notifications.orders_sms;

var params = apiHelpers.buildHeaderWithBearerAndContentType(token);
const params = apiHelpers.buildHeaderWithBearerAndContentType(token);

var response = http.post(endpoint, serializedOrder, params);

return response;
return http.post(endpoint, serializedOrder, params);
}

export function getById(id, token) {
var endpoint = config.notifications.orders_fromId(id);
const endpoint = config.notifications.orders_fromId(id);

return getByUrl(endpoint, token);
}

export function getByUrl(url, token) {
var params = apiHelpers.buildHeaderWithBearer(token);
var response = http.get(url, params);
const params = apiHelpers.buildHeaderWithBearer(token);

return response;
return http.get(url, params);
}

export function getBySendersReference(sendersReference, token) {
var endpoint =
config.notifications.orders_fromSendersRef(sendersReference);
var params = apiHelpers.buildHeaderWithBearer(token);
var response = http.get(endpoint, params);
return response;
const endpoint = config.notifications.orders_fromSendersRef(sendersReference);

const params = apiHelpers.buildHeaderWithBearer(token);

return http.get(endpoint, params);
}

export function getWithStatus(orderId, token) {
var endpoint = config.notifications.orders_status(orderId);
var params = apiHelpers.buildHeaderWithBearer(token);
var response = http.get(endpoint, params);
return response;
const endpoint = config.notifications.orders_status(orderId);

const params = apiHelpers.buildHeaderWithBearer(token);

return http.get(endpoint, params);
}
61 changes: 35 additions & 26 deletions test/k6/src/api/token-generator.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
import http from "k6/http";
import { check } from "k6";
import encoding from "k6/encoding";

import * as config from "../config.js";
import { stopIterationOnFail } from "../errorhandler.js";
import * as apiHelpers from "../apiHelpers.js";
import { stopIterationOnFail } from "../errorhandler.js";

const tokenGeneratorUserName = __ENV.tokenGeneratorUserName;
const tokenGeneratorUserPwd = __ENV.tokenGeneratorUserPwd;
const tokenGeneratorUserName = __ENV.tokenGeneratorUserName;

/*
Generate enterprise token for test environment
*/
* Generate enterprise token for test environment.
*
* @param {Object} queryParams - The query parameters to be included in the token generation request.
* @returns {string} The generated enterprise token.
*/
export function generateEnterpriseToken(queryParams) {
var endpoint =
config.tokenGenerator.getEnterpriseToken +
apiHelpers.buildQueryParametersForEndpoint(queryParams);
const endpoint =
config.tokenGenerator.getEnterpriseToken +
apiHelpers.buildQueryParametersForEndpoint(queryParams);

return generateToken(endpoint);
return generateToken(endpoint);
}

export function generatePersonalToken(queryParams) {
var endpoint =
config.tokenGenerator.getPersonalToken +
apiHelpers.buildQueryParametersForEndpoint(queryParams);
/**
* Generates a token by making an HTTP GET request to the specified Token endpoint.
*
* @param {string} endpoint - The endpoint URL to which the token generation request is sent.
* @returns {string} The generated token.
*/
function generateToken(endpoint) {
if (!tokenGeneratorUserName) {
stopIterationOnFail(`Invalid value for environment variable 'tokenGeneratorUserName': '${tokenGeneratorUserName}'.`, false);
}

return generateToken(endpoint);
}
if (!tokenGeneratorUserPwd) {
stopIterationOnFail(`Invalid value for environment variable 'tokenGeneratorUserPwd': '${tokenGeneratorUserPwd}'.`, false);
}

function generateToken(endpoint) {
const credentials = `${tokenGeneratorUserName}:${tokenGeneratorUserPwd}`;
const encodedCredentials = encoding.b64encode(credentials);
const credentials = `${tokenGeneratorUserName}:${tokenGeneratorUserPwd}`;

const encodedCredentials = encoding.b64encode(credentials);

const params = apiHelpers.buildHeaderWithBasic(encodedCredentials);

var params = apiHelpers.buildHeaderWithBasic(encodedCredentials);
const response = http.get(endpoint, params);

var response = http.get(endpoint, params);
if (response.status != 200) {
stopIterationOnFail("Token generation failed", false);
}

if (response.status != 200) {
stopIterationOnFail("Token generation failed", false);
}
const token = response.body;

var token = response.body;
return token;
return token;
}
Loading
Loading