Skip to content

Commit

Permalink
fix(lint): fix issue #1359
Browse files Browse the repository at this point in the history
Signed-off-by: katherine <krosenk729@gmail.com>
  • Loading branch information
krosenk729 authored and petermetz committed Oct 27, 2021
1 parent 50e666f commit d067df2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 57 deletions.
4 changes: 4 additions & 0 deletions packages/cactus-plugin-keychain-vault/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@
},
"devDependencies": {
"@hyperledger/cactus-test-tooling": "1.0.0-rc.1",
"@types/body-parser": "1.19.1",
"@types/express": "4.17.13",
"@types/internal-ip": "4.1.0",
"@types/request": "2.48.7",
"@types/tape-promise": "4.0.1",
"@types/uuid": "8.3.1",
"internal-ip": "6.2.0",
"openapi-types": "9.1.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import test, { Test } from "tape-promise/tape";
import { v4 as internalIpV4 } from "internal-ip";

import { AxiosError } from "axios";
import express from "express";
import bodyParser from "body-parser";
import http from "http";
import { AddressInfo } from "net";

import { v4 as uuidv4 } from "uuid";
import {
Containers,
K_DEFAULT_VAULT_DEV_ROOT_TOKEN,
K_DEFAULT_VAULT_HTTP_PORT,
VaultTestServer,
} from "@hyperledger/cactus-test-tooling";

import { v4 as uuidv4 } from "uuid";

import {
LogLevelDesc,
IListenOptions,
Expand Down Expand Up @@ -139,98 +136,97 @@ test(`${testCase}`, async (t: Test) => {

test(`${testCase} - ${fSet} - ${cWithoutParams}`, async (t2: Test) => {
try {
await apiClient.setKeychainEntryV1(({
await apiClient.setKeychainEntryV1({
value: value1,
} as any) as SetKeychainEntryRequest);
} catch (e) {
} as SetKeychainEntryRequest);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fSet} without required key: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(fields.includes("key"), "Rejected because key is required");
t2.ok(fields?.includes("key"), "Rejected because key is required");
}
t2.end();
});

test(`${testCase} - ${fHas} - ${cWithoutParams}`, async (t2: Test) => {
try {
await apiClient.hasKeychainEntryV1(
({} as any) as HasKeychainEntryRequestV1,
);
} catch (e) {
await apiClient.hasKeychainEntryV1({} as HasKeychainEntryRequestV1);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fHas} without required key: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(fields.includes("key"), "Rejected because key is required");
t2.ok(fields?.includes("key"), "Rejected because key is required");
}
t2.end();
});

test(`${testCase} - ${fGet} - ${cWithoutParams}`, async (t2: Test) => {
try {
await apiClient.getKeychainEntryV1(
({} as any) as GetKeychainEntryRequest,
);
} catch (e) {
await apiClient.getKeychainEntryV1({} as GetKeychainEntryRequest);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fGet} without required key: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(fields.includes("key"), "Rejected because key is required");
t2.ok(fields?.includes("key"), "Rejected because key is required");
}
t2.end();
});

test(`${testCase} - ${fDelete} - ${cWithoutParams}`, async (t2: Test) => {
try {
await apiClient.deleteKeychainEntryV1(
({} as any) as DeleteKeychainEntryRequestV1,
);
} catch (e) {
await apiClient.deleteKeychainEntryV1({} as DeleteKeychainEntryRequestV1);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fDelete} without required key: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(fields.includes("key"), "Rejected because key is required");
t2.ok(fields?.includes("key"), "Rejected because key is required");
}
t2.end();
});

test(`${testCase} - ${fSet} - ${cInvalidParams}`, async (t2: Test) => {
try {
await apiClient.setKeychainEntryV1(({
await apiClient.setKeychainEntryV1({
key: key1,
value: value1,
fake: 4,
} as any) as SetKeychainEntryRequest);
} catch (e) {
} as SetKeychainEntryRequest);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fSet} with fake=4: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(
fields.includes("fake"),
fields?.includes("fake"),
"Rejected because fake is not a valid parameter",
);
}
Expand All @@ -239,21 +235,22 @@ test(`${testCase}`, async (t: Test) => {

test(`${testCase} - ${fHas} - ${cInvalidParams}`, async (t2: Test) => {
try {
await apiClient.hasKeychainEntryV1(({
await apiClient.hasKeychainEntryV1({
key: key1,
fake: 4,
} as any) as HasKeychainEntryRequestV1);
} catch (e) {
} as HasKeychainEntryRequestV1);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fHas} with fake=4: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param) =>
param.path.replace(".body.", ""),
);
t2.ok(
fields.includes("fake"),
fields?.includes("fake"),
"Rejected because fake is not a valid parameter",
);
}
Expand All @@ -262,19 +259,20 @@ test(`${testCase}`, async (t: Test) => {

test(`${testCase} - ${fGet} - ${cInvalidParams}`, async (t2: Test) => {
try {
await apiClient.getKeychainEntryV1(({
await apiClient.getKeychainEntryV1({
key: key1,
fake: 4,
} as any) as GetKeychainEntryRequest);
} catch (e) {
} as GetKeychainEntryRequest);
} catch (err) {
const e = err as AxiosError<{ path: string }[]>;
t2.equal(
e.response.status,
e?.response?.status,
400,
`Endpoint ${fGet} with fake=4: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
param.path.replace(".body.", ""),
);
const fields =
e?.response?.data.map((param) => param.path.replace(".body.", "")) ||
[];
t2.ok(
fields.includes("fake"),
"Rejected because fake is not a valid parameter",
Expand All @@ -285,21 +283,22 @@ test(`${testCase}`, async (t: Test) => {

test(`${testCase} - ${fDelete} - ${cInvalidParams}`, async (t2: Test) => {
try {
await apiClient.deleteKeychainEntryV1(({
await apiClient.deleteKeychainEntryV1({
key: key1,
fake: 4,
} as any) as GetKeychainEntryRequest);
} catch (e) {
} as GetKeychainEntryRequest);
} catch (err) {
const e = err as AxiosError;
t2.equal(
e.response.status,
(e as AxiosError)?.response?.status,
400,
`Endpoint ${fDelete} with fake=4: response.status === 400 OK`,
);
const fields = e.response.data.map((param: any) =>
const fields = e?.response?.data.map((param: { path: string }) =>
param.path.replace(".body.", ""),
);
t2.ok(
fields.includes("fake"),
fields?.includes("fake"),
"Rejected because fake is not a valid parameter",
);
}
Expand Down

0 comments on commit d067df2

Please sign in to comment.