Skip to content

Commit ae62345

Browse files
Merge pull request #11 from andresWeitzel/security-03-fix-hard-coded-credentials-test
security-03-fix-hard-coded-credentials-test
2 parents d5bfb93 + c4835c8 commit ae62345

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ API_GRPC_IP_ENDPOINT_ADDRESS_NAME_URL = '/api/v1/grpc-ip/'
99

1010
# Whois config
1111
WHOIS_BASE_URL = "https://ipwho.is/"
12+
13+
# Mock testing
14+
MOCK_STRING_01 = ""
15+
MOCK_NUMBER_01 = 8123891273812
16+
MOCK_INVALID_IP_01 = "192.77"
17+
MOCK_VALID_IP_01 = "8.8.8.8"
18+
MOCK_OBJECT_VALUE_01 = "mock_object_value"

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
//For using environment variables with .env
3+
const dotenv = require("dotenv");
4+
5+
module.exports = {
6+
setupFiles: ["dotenv/config"]
7+
}

src/test/unit-test/api-integration/helpers/format/address.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const {
44
splitAddressByLastDot,
55
} = require("../../../../../api-integration/helpers/format/address");
66
//Const
7-
const MOCK_STRING_VALUE = "";
7+
const MOCK_STRING_01 = process.env.MOCK_STRING_01;
8+
const MOCK_NUMBER_01 = parseInt(process.env.MOCK_NUMBER_01);
89
//Vars
910
let msg;
1011
let splitAddressByLastDotResult;
@@ -20,26 +21,24 @@ describe("- splitAddressByLastDot helper (Unit Test)", () => {
2021
msg =
2122
"Should return a object type if a valid argument is passed (This function expects a single argument)";
2223
it(msg, async () => {
23-
splitAddressByLastDotResult = await splitAddressByLastDot(
24-
MOCK_STRING_VALUE
25-
);
24+
splitAddressByLastDotResult = await splitAddressByLastDot(MOCK_STRING_01);
2625
await expect(typeof splitAddressByLastDotResult == "object").toBe(true);
2726
});
2827

2928
msg =
3029
"Should return a object type if two valid arguments are passed (This function expects a single argument)";
3130
it(msg, async () => {
3231
splitAddressByLastDotResult = await splitAddressByLastDot(
33-
MOCK_STRING_VALUE,
34-
MOCK_STRING_VALUE
32+
MOCK_STRING_01,
33+
MOCK_STRING_01
3534
);
3635
await expect(typeof splitAddressByLastDotResult == "object").toBe(true);
3736
});
38-
37+
3938
msg =
4039
"Should return a string type if an invalid argument is passed (This function expects a single argument)";
4140
it(msg, async () => {
42-
splitAddressByLastDotResult = await splitAddressByLastDot(122212131);
41+
splitAddressByLastDotResult = await splitAddressByLastDot(MOCK_NUMBER_01);
4342
await expect(typeof splitAddressByLastDotResult == "string").toBe(true);
4443
});
4544

src/test/unit-test/api-integration/helpers/request/get-data-from-address.test.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,74 @@ const {
44
getDataFromSpecificAddress,
55
} = require("../../../../../api-integration/helpers/request/get-data-from-address");
66
//Const
7-
const MOCK_OBJECT_VALUE = { mock_object_key: "mock_object_value" };
8-
const MOCK_INVALID_IP_VALUE = "192.77";
9-
const MOCK_VALID_IP_VALUE = "8.8.8.8";
7+
const MOCK_OBJECT_KEY_01 = process.env.MOCK_OBJECT_KEY_01;
8+
const MOCK_OBJECT_01 = { mock_object_key: MOCK_OBJECT_KEY_01 };
9+
const MOCK_INVALID_IP_VALUE_01 = process.env.MOCK_INVALID_IP_01;
10+
const MOCK_VALID_IP_VALUE_01 = process.env.MOCK_VALID_IP_01;
1011
//Vars
1112
let msg;
1213
let getDataFromSpecificAddressResult;
1314

1415
describe("- getDataFromSpecificAddress helper (Unit Test)", () => {
1516
describe("1) Check cases for arguments.", () => {
1617
msg =
17-
"Should return a string type if no arguments are passed (This function expects a single argument of string type)";
18+
"Should return a object type if no arguments are passed (This function expects a single argument of string type)";
1819
it(msg, async () => {
1920
getDataFromSpecificAddressResult = await getDataFromSpecificAddress();
20-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
21+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
2122
true
2223
);
2324
});
2425

2526
msg =
26-
"Should return a string type if not string argument is passed (This function expects a single argument of string type)";
27+
"Should return a object type if not string argument is passed (This function expects a single argument of string type)";
2728
it(msg, async () => {
2829
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
29-
MOCK_OBJECT_VALUE
30+
MOCK_OBJECT_01
3031
);
31-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
32+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
3233
true
3334
);
3435
});
3536

3637
msg =
37-
"Should return a string type if an invalid ip is passed (This function expects a single argument of string type)";
38+
"Should return a object type if an invalid ip is passed (This function expects a single argument of string type)";
3839
it(msg, async () => {
3940
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
40-
MOCK_INVALID_IP_VALUE
41+
MOCK_INVALID_IP_VALUE_01
4142
);
42-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
43+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
4344
true
4445
);
4546
});
4647

4748
msg =
48-
"Should return a string type if a valid ip is passed (This function expects a single argument of string type)";
49+
"Should return a object type if a valid ip is passed (This function expects a single argument of string type)";
4950
it(msg, async () => {
5051
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
51-
MOCK_VALID_IP_VALUE
52+
MOCK_VALID_IP_VALUE_01
5253
);
53-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
54+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
5455
true
5556
);
5657
});
5758

5859
msg =
59-
"Should return a string type if a null value is passed (This function expects a single argument of string type)";
60+
"Should return a object type if a null value is passed (This function expects a single argument of string type)";
6061
it(msg, async () => {
6162
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(null);
62-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
63+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
6364
true
6465
);
6566
});
6667

6768
msg =
68-
"Should return a string type if an undefined value is passed (This function expects a single argument of string type)";
69+
"Should return a object type if an undefined value is passed (This function expects a single argument of string type)";
6970
it(msg, async () => {
7071
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
7172
undefined
7273
);
73-
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
74+
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
7475
true
7576
);
7677
});
@@ -119,18 +120,13 @@ describe("- getDataFromSpecificAddress helper (Unit Test)", () => {
119120
});
120121

121122
msg =
122-
"Should return a string type with 'ERROR in getDataFromSpecificAddress helper function.' value if a new Error is passed for arguments.";
123+
"Should return a object type if a new Error is passed for arguments.";
123124
it(msg, async () => {
124125
let newError = new Error();
125-
const GET_DATA_FROM_SPECIFIC_ADDRESS_ERROR_NAME =
126-
"ERROR in getDataFromSpecificAddress helper function.";
127-
128126
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
129127
newError
130128
);
131-
await expect(getDataFromSpecificAddressResult).toMatch(
132-
GET_DATA_FROM_SPECIFIC_ADDRESS_ERROR_NAME
133-
);
129+
await expect(typeof getDataFromSpecificAddressResult == "object");
134130
});
135131
});
136132
});

0 commit comments

Comments
 (0)