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

Flexible data handling #87

Merged
merged 12 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 22 additions & 20 deletions docs/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ Global namespace for util modules.
* [.success(message)](#util.console.success)
* [.info(message)](#util.console.info)
* [.data](#util.data)
* [.getData(filename)](#util.data.getData) ⇒ <code>String</code>
* [.getSecureData(filename)](#util.data.getSecureData) ⇒ <code>String</code>
* [.getData(filename, [source])](#util.data.getData) ⇒ <code>String</code>
* [.getSecureData(filename, [source])](#util.data.getSecureData) ⇒ <code>String</code>
* [.decrypt(data)](#util.data.decrypt) ⇒ <code>String</code>
* [.file](#util.file)
* [.upload(files, [selector])](#util.file.upload)
Expand Down Expand Up @@ -979,37 +979,39 @@ util.console.success("The document has been saved.");
**Kind**: static class of [<code>util</code>](#util)

* [.data](#util.data)
* [.getData(filename)](#util.data.getData) ⇒ <code>String</code>
* [.getSecureData(filename)](#util.data.getSecureData) ⇒ <code>String</code>
* [.getData(filename, [source])](#util.data.getData) ⇒ <code>String</code>
* [.getSecureData(filename, [source])](#util.data.getSecureData) ⇒ <code>String</code>
* [.decrypt(data)](#util.data.decrypt) ⇒ <code>String</code>

<a name="util.data.getData"></a>

#### data.getData(filename) ⇒ <code>String</code>
#### data.getData(filename, [source]) ⇒ <code>String</code>
Returns the data object with the given filename (JSON, stored in data folder).

**Kind**: static method of [<code>data</code>](#util.data)
**Returns**: <code>String</code> - The data object.

| Param | Type | Description |
| --- | --- | --- |
| filename | <code>String</code> | The name of the data file. |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| filename | <code>String</code> | | The name of the data file. |
| [source] | <code>String</code> | <code>data</code> | The source key defined under params.import of the config file. |

**Example**
```js
const data = util.data.getData("myTest");
```
<a name="util.data.getSecureData"></a>

#### data.getSecureData(filename) ⇒ <code>String</code>
#### data.getSecureData(filename, [source]) ⇒ <code>String</code>
Returns and encrypts the data object with the given filename (JSON, stored in data folder). Will return the local file object if private key is not accessible.

**Kind**: static method of [<code>data</code>](#util.data)
**Returns**: <code>String</code> - The encrypted or local data object.

| Param | Type | Description |
| --- | --- | --- |
| filename | <code>String</code> | The name of the data file (without suffix '.secure' or '.local'). |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| filename | <code>String</code> | | The name of the data file (without suffix '.secure' or '.local'). |
| [source] | <code>String</code> | <code>data</code> | The source key defined under params.import of the config file. |

**Example**
```js
Expand Down Expand Up @@ -1444,7 +1446,7 @@ Global namespace for UI5 modules.
* [.loginFiori(username, [password], [verify])](#ui5.session.loginFiori)
* [.loginSapCloud(username, [password], [verify])](#ui5.session.loginSapCloud)
* [.loginCustom(username, [password], usernameFieldSelector, passwordFieldSelector, logonButtonSelector, [verify])](#ui5.session.loginCustom)
* [.loginCustomViaConfig(username, password, [verify])](#ui5.session.loginCustomViaConfig)
* [.loginCustomViaConfig(username, [password], [verify])](#ui5.session.loginCustomViaConfig)
* [.logout([verify])](#ui5.session.logout)
* [.switchUser(username, [password], [authenticator], [wait])](#ui5.session.switchUser)
* [.expectLogoutText()](#ui5.session.expectLogoutText)
Expand Down Expand Up @@ -3086,7 +3088,7 @@ await ui5.qunit.executeTests("path/to/qunit.html");
* [.loginFiori(username, [password], [verify])](#ui5.session.loginFiori)
* [.loginSapCloud(username, [password], [verify])](#ui5.session.loginSapCloud)
* [.loginCustom(username, [password], usernameFieldSelector, passwordFieldSelector, logonButtonSelector, [verify])](#ui5.session.loginCustom)
* [.loginCustomViaConfig(username, password, [verify])](#ui5.session.loginCustomViaConfig)
* [.loginCustomViaConfig(username, [password], [verify])](#ui5.session.loginCustomViaConfig)
* [.logout([verify])](#ui5.session.logout)
* [.switchUser(username, [password], [authenticator], [wait])](#ui5.session.switchUser)
* [.expectLogoutText()](#ui5.session.expectLogoutText)
Expand All @@ -3101,7 +3103,7 @@ Login with specific username and password. This function works for both fiori an
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| username | <code>String</code> | | The username. |
| [password] | <code>String</code> | <code>&quot;super-duper-sensitive-pw&quot;</code> | The password. |
| [password] | <code>String</code> | | The password. |
| [verify] | <code>Boolean</code> | <code>false</code> | Specifies if the function will check the shell header after logging in. |
| [timeout] | <code>Number</code> | <code>30000</code> | The timeout to wait (ms). |

Expand All @@ -3123,7 +3125,7 @@ Login with fioriForm and specific username and password.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| username | <code>String</code> | | The username. |
| [password] | <code>String</code> | <code>&quot;super-duper-sensitive-pw&quot;</code> | The password. |
| [password] | <code>String</code> | | The password. |
| [verify] | <code>Boolean</code> | <code>false</code> | Specifies if the function will check the shell header after logging in. |

**Example**
Expand All @@ -3140,7 +3142,7 @@ Login with sapCloud form and specific username and password.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| username | <code>String</code> | | The username. |
| [password] | <code>String</code> | <code>&quot;super-duper-sensitive-pw&quot;</code> | The password. |
| [password] | <code>String</code> | | The password. |
| [verify] | <code>Boolean</code> | <code>false</code> | Specifies if the function will check the shell header after logging in. |

**Example**
Expand Down Expand Up @@ -3169,15 +3171,15 @@ await ui5.session.loginCustom("JOHN_DOE", "abc123!", "#username", #password, "#l
```
<a name="ui5.session.loginCustomViaConfig"></a>

#### session.loginCustomViaConfig(username, password, [verify])
#### session.loginCustomViaConfig(username, [password], [verify])
Login with specific username and password. The selectors will be taken from the config.

**Kind**: static method of [<code>session</code>](#ui5.session)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| username | <code>String</code> | | The username. Can be specified in spec or config. If specified in both credentials will be taken from config. |
| password | <code>String</code> | <code>&quot;super-duper-sensitive-pw&quot;</code> | The password. Can be specified in spec or config. If specified in both credentials will be taken from config. |
| [password] | <code>String</code> | | The password. Can be specified in spec or config. If specified in both credentials will be taken from config. |
| [verify] | <code>Boolean</code> | <code>false</code> | Specifies if the function will check the shell header after logging in. |

**Example**
Expand Down Expand Up @@ -3230,7 +3232,7 @@ switches the user according to the passed username and password.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| username | <code>String</code> | | The username. |
| [password] | <code>String</code> | <code>&quot;super-duper-sensitive-pw&quot;</code> | The password. |
| [password] | <code>String</code> | | The password. |
| [authenticator] | <code>Object</code> | | The login form type. Set to null to use generic login. |
| [wait] | <code>Number</code> | <code>10000</code> | The waiting time between logout and login (ms). |

Expand Down
27 changes: 14 additions & 13 deletions src/reuse/modules/util/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
* @memberof util
*/
export class Data {

/**
* @function getData
* @memberOf util.data
* @description Returns the data object with the given filename (JSON, stored in data folder).
* @param {String} filename - The name of the data file.
* @param {String} [source=data] - The source key defined under params.import of the config file.
* @returns {String} The data object.
* @example const data = util.data.getData("myTest");
*/
getData(filename: string): string {
if (browser.config.params && browser.config.params.import && browser.config.params.import.data) {
if (browser.config.params.import.data[filename]) {
return browser.config.params.import.data[filename];
getData(filename: string, source: string = "data"): string {
if (browser.config.params && browser.config.params.import && browser.config.params.import[source]) {
if (browser.config.params.import[source][filename]) {
return browser.config.params.import[source][filename];
} else {
throw new Error(`Function 'getData' failed. No file with name ${filename} found'`);
throw new Error(`Function 'getData' failed. File '${filename}.json' empty or not defined under '${source}'`);
}
} else {
throw new Error(`Function 'getData' failed. No data path defined in config.`);
throw new Error(`Function 'getData' failed. Data path '${source}' not defined in config.`);
}
}

Expand All @@ -30,10 +30,11 @@ export class Data {
* @memberOf util.data
* @description Returns and encrypts the data object with the given filename (JSON, stored in data folder). Will return the local file object if private key is not accessible.
* @param {String} filename - The name of the data file (without suffix '.secure' or '.local').
* @param {String} [source=data] - The source key defined under params.import of the config file.
* @returns {String} The encrypted or local data object.
* @example const secureData = util.data.getSecureData("myTest");
*/
getSecureData(filename: string): string {
getSecureData(filename: string, source: string = "data"): string {
const privateKeyFound = global.util.data.privateKeyFound === true;

if (privateKeyFound) {
Expand All @@ -43,20 +44,20 @@ export class Data {
filename = `${filename}.local`;
}

if (browser.config.params && browser.config.params.import && browser.config.params.import.data) {
if (browser.config.params.import.data[filename]) {
const data = browser.config.params.import.data[filename];
if (browser.config.params && browser.config.params.import && browser.config.params.import[source]) {
if (browser.config.params.import[source][filename]) {
const data = browser.config.params.import[source][filename];

if (privateKeyFound) {
this._decryptRecursively(data);
}

return data;
} else {
throw new Error(`Function 'getSecureData' failed. File '${filename}.json' not found'`);
throw new Error(`Function 'getSecureData' failed. File '${filename}.json' empty or not defined under '${source}'`);
}
} else {
throw new Error(`Function 'getSecureData' failed. No data path defined in config.`);
throw new Error(`Function 'getSecureData' failed. Data path '${source}' not defined in config.`);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/reuse/util/data/customSourceData/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "TEST"
}
5 changes: 5 additions & 0 deletions test/reuse/util/data/customSourceData/test.secure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"session": {
"password": "b1512310be1b4ae516a92bab1f857fc6018abe6e8199622db77a621b21ab1d7b0aeede946829ad6d46ec4d8f349e0a27452abe8fd0f7f035a309627e80a066a400ad06456ae6e6202287c7259b5703e8df768e76708c0f8494c2245eee5a841e1ab4ecd909347561cb92eba4ff53f7e288a31d295f475b1a6a00b804090d7bc15eb2108f6ce842fdee574d95c8fa562f4a927aaaea77c5eaf66330bfcb6445ee55c58815d30eb94845a19f3080e89a96cb9fcacfc51a1043dff1a99086d3be86e4529e9ddd381086a167703d5bff19e3060fec0e59b6a2d3d383c731bff89e26cc322d5436c5f654aa4df99977c770580220cad7075fc786a5d6310e49881b8ee9e3614339ce3d7f991d801f6e469ebff38cbda7fa479e6949a71580c8cd53816f72765dd0fe15feeab30424e950b37b8cfa0900d36295208b900d0923ac9b99f8bd5707a6095bdb4c995286787dc3fa058c462f041879061afd5157a207eca7"
}
}
19 changes: 18 additions & 1 deletion test/reuse/util/data/getData.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("data - getData", function() {
describe("data - getData - default source", function() {

let dataAct;

Expand All @@ -13,3 +13,20 @@ describe("data - getData", function() {
});

});

describe("data - getData - custom source", function() {

let dataAct;

it("Execution & Verification", function () {
const source = "customSourceData";
const data = util.data.getData("test", source);
dataAct = data.test;
});

it("Verification", function () {
const dataExp = "TEST";
common.assertion.expectEqual(dataAct, dataExp);
});

});
19 changes: 18 additions & 1 deletion test/reuse/util/data/getSecureData.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("data - getSecureData", function() {
describe("data - getSecureData - default source", function() {

let data;

Expand Down Expand Up @@ -32,6 +32,23 @@ describe("data - getSecureData", function() {

});

describe("data - getSecureData - custom source", function() {

let data;

it("Execution", function () {
const source = "customSourceData";
data = util.data.getSecureData("test", source);
});

it("Verification", function () {
const dataExp = "super-duper-sensitive-pw";
const dataAct = data.session.password;
common.assertion.expectEqual(dataAct, dataExp);
});

});

// =================================== KEEP DISABLED ===================================
// Can't be executed in pipeline because file is missing. Add the following to "data" folder to execute locally:

Expand Down
3 changes: 2 additions & 1 deletion test/reuse/util/data/test.data.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ exports.config = merge(profile.config, {

params: {
import: {
data: "./data/"
data: "./data/",
customSourceData: "./customSourceData"
}
},

Expand Down