From ad098f3478e3387e390edcaa5965ab99d9a7dcb8 Mon Sep 17 00:00:00 2001 From: akumar Date: Tue, 13 Feb 2024 17:29:55 +0100 Subject: [PATCH] fix: unit tests --- src/core/resource_adapters/gql.ts | 4 +++- test/access_control.json | 27 --------------------------- test/acl.spec.ts | 2 +- test/core.spec.ts | 28 +++++++++++++++++++++++++++- 4 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 test/access_control.json diff --git a/src/core/resource_adapters/gql.ts b/src/core/resource_adapters/gql.ts index df4b36d..fda3e36 100644 --- a/src/core/resource_adapters/gql.ts +++ b/src/core/resource_adapters/gql.ts @@ -1,5 +1,5 @@ import { ResourceAdapter, QueryResult } from './adapter.js'; -import { ApolloClient } from 'apollo-client'; +import pkg from 'apollo-client'; import gql from 'graphql-tag'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { HttpLink } from 'apollo-link-http'; @@ -9,6 +9,8 @@ import { Request } from '@restorecommerce/rc-grpc-clients/dist/generated-server/ import * as errors from '../errors.js'; import fetch from 'cross-fetch'; +const { ApolloClient } = pkg; + export class GraphQLAdapter implements ResourceAdapter { constructor(private url: string, private logger: any, private clientOpts: any = {}) { if (_.isEmpty(url) || _.isNil(url)) { diff --git a/test/access_control.json b/test/access_control.json deleted file mode 100644 index b78390b..0000000 --- a/test/access_control.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "combiningAlgorithms": [ - { - "urn": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides", - "method": "denyOverrides" - }, - { - "urn": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides", - "method": "permitOverrides" - }, - { - "urn":"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:first-applicable", - "method":"firstApplicable" - } - ], - "urns": { - "roleScopingEntity": "urn:restorecommerce:acs:names:roleScopingEntity", - "roleScopingInstance": "urn:restorecommerce:acs:names:roleScopingInstance", - "hierarchicalRoleScoping": "urn:restorecommerce:acs:names:hierarchicalRoleScoping", - "ownerEntity": "urn:restorecommerce:acs:names:ownerIndicatoryEntity", - "ownerInstance": "urn:restorecommerce:acs:names:ownerInstance", - "resourceID": "urn:oasis:names:tc:xacml:1.0:resource:resource-id", - "entity": "urn:restorecommerce:acs:names:model:entity", - "role": "urn:restorecommerce:acs:names:role", - "operation": "urn:restorecommerce:acs:names:operation" - } -} diff --git a/test/acl.spec.ts b/test/acl.spec.ts index a237356..9ffef26 100644 --- a/test/acl.spec.ts +++ b/test/acl.spec.ts @@ -1,6 +1,6 @@ import * as mocha from 'mocha'; import * as should from 'should'; -import { Worker } from '../lib/worker.js'; +import { Worker } from '../src/worker'; import * as testUtils from './utils.js'; import * as yaml from 'js-yaml'; import * as fs from 'node:fs'; diff --git a/test/core.spec.ts b/test/core.spec.ts index d498487..9bd86a6 100644 --- a/test/core.spec.ts +++ b/test/core.spec.ts @@ -9,7 +9,33 @@ import { UserServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/gen import { Request, Response, Response_Decision } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/access_control.js'; import { cfg, logger } from './utils.js'; -const acConfig = require('./access_control.json'); +const acConfig = { + "combiningAlgorithms": [ + { + "urn": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides", + "method": "denyOverrides" + }, + { + "urn": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides", + "method": "permitOverrides" + }, + { + "urn": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:first-applicable", + "method": "firstApplicable" + } + ], + "urns": { + "roleScopingEntity": "urn:restorecommerce:acs:names:roleScopingEntity", + "roleScopingInstance": "urn:restorecommerce:acs:names:roleScopingInstance", + "hierarchicalRoleScoping": "urn:restorecommerce:acs:names:hierarchicalRoleScoping", + "ownerEntity": "urn:restorecommerce:acs:names:ownerIndicatoryEntity", + "ownerInstance": "urn:restorecommerce:acs:names:ownerInstance", + "resourceID": "urn:oasis:names:tc:xacml:1.0:resource:resource-id", + "entity": "urn:restorecommerce:acs:names:model:entity", + "role": "urn:restorecommerce:acs:names:role", + "operation": "urn:restorecommerce:acs:names:operation" + } +}; let ac: AccessController; let request: Request;