Bug 40174: Introduce Cypress auth plugin
So we can easily retrieve the value for the Authorization header.
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 52c57538c7)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
9f20519c9c
commit
2acffbcc5d
|
|
@ -16,4 +16,8 @@ export default defineConfig({
|
|||
specPattern: "t/cypress/integration/**/*.*",
|
||||
supportFile: "t/cypress/support/e2e.js",
|
||||
},
|
||||
env: {
|
||||
apiUsername: "koha",
|
||||
apiPassword: "koha",
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
const { Buffer } = require("buffer");
|
||||
|
||||
const getBasicAuthHeader = (username, password) => {
|
||||
const credentials = Buffer.from(`${username}:${password}`).toString(
|
||||
"base64"
|
||||
);
|
||||
return `Basic ${credentials}`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getBasicAuthHeader,
|
||||
};
|
||||
|
|
@ -8,12 +8,19 @@ const {
|
|||
deleteSampleObjects,
|
||||
} = require("./insertData.js");
|
||||
|
||||
const { getBasicAuthHeader } = require("./auth.js");
|
||||
|
||||
const { query } = require("./db.js");
|
||||
|
||||
const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js");
|
||||
|
||||
module.exports = (on, config) => {
|
||||
const baseUrl = config.baseUrl;
|
||||
const authHeader = getBasicAuthHeader(
|
||||
config.env.apiUsername,
|
||||
config.env.apiPassword
|
||||
);
|
||||
|
||||
on("dev-server:start", options =>
|
||||
startDevServer({
|
||||
options,
|
||||
|
|
@ -21,10 +28,16 @@ module.exports = (on, config) => {
|
|||
);
|
||||
|
||||
on("task", {
|
||||
getBasicAuthHeader() {
|
||||
return getBasicAuthHeader(
|
||||
config.env.apiUsername,
|
||||
config.env.apiPassword
|
||||
);
|
||||
},
|
||||
buildSampleObject,
|
||||
buildSampleObjects,
|
||||
insertSampleBiblio({ item_count }) {
|
||||
return insertSampleBiblio(item_count, baseUrl);
|
||||
return insertSampleBiblio(item_count, baseUrl, authHeader);
|
||||
},
|
||||
insertObject({ type, object }) {
|
||||
return insertObject(type, object, baseUrl, authHeader);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ const { buildSampleObject, buildSampleObjects } = require("./mockData.js");
|
|||
const { query } = require("./db.js");
|
||||
|
||||
const { APIClient } = require("./dist/api-client.cjs.js");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
const insertSampleBiblio = async (item_count, baseUrl) => {
|
||||
const insertSampleBiblio = async (item_count, baseUrl, authHeader) => {
|
||||
let client = APIClient.default;
|
||||
let generated_objects = {};
|
||||
const objects = [{ object: "library" }, { object: "item_type" }];
|
||||
|
|
@ -53,13 +52,12 @@ const insertSampleBiblio = async (item_count, baseUrl) => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const credentials = Buffer.from("koha:koha").toString("base64");
|
||||
let result = await client.koha.post({
|
||||
endpoint: `${baseUrl}/api/v1/biblios`,
|
||||
headers: {
|
||||
"Content-Type": "application/marc-in-json",
|
||||
"x-confirm-not-duplicate": 1,
|
||||
Authorization: "Basic " + credentials,
|
||||
Authorization: authHeader,
|
||||
},
|
||||
body: biblio,
|
||||
});
|
||||
|
|
@ -132,7 +130,7 @@ const insertSampleBiblio = async (item_count, baseUrl) => {
|
|||
body: item,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Basic " + credentials,
|
||||
Authorization: authHeader,
|
||||
},
|
||||
})
|
||||
.then(i => createdItems.push(i));
|
||||
|
|
|
|||
Loading…
Reference in New Issue