@labdigital/commercetools-mock 0.5.14 → 0.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare const maskSecretValue: <T>(resource: T, path: string) => T;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.14",
2
+ "version": "0.5.15",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1,22 @@
1
+ import { json } from 'express'
2
+
3
+ export const maskSecretValue = <T>(resource: T, path: string): T => {
4
+ const parts = path.split('.')
5
+ const clone = JSON.parse(JSON.stringify(resource))
6
+ let val = clone
7
+
8
+ const target = parts.pop()
9
+ for (let i = 0; i < parts.length; i++) {
10
+ const part = parts[i]
11
+ val = val[part]
12
+
13
+ if (val == undefined) {
14
+ return resource
15
+ }
16
+ }
17
+
18
+ if (val && target && val[target]) {
19
+ val[target] = '****'
20
+ }
21
+ return clone
22
+ }
@@ -18,11 +18,17 @@ import { Writable } from 'types'
18
18
  import { checkConcurrentModification } from './errors'
19
19
  import { CommercetoolsError } from '../exceptions'
20
20
  import { AbstractRepository } from './abstract'
21
+ import { maskSecretValue } from '../lib/masking'
21
22
 
22
23
  export class ProjectRepository extends AbstractRepository {
23
24
  get(projectKey: string): Project | null {
24
25
  const data = this._storage.getProject(projectKey)
25
- return this._storage.getProject(projectKey)
26
+ const resource = this._storage.getProject(projectKey)
27
+ const masked = maskSecretValue<Project>(
28
+ resource,
29
+ 'externalOAuth.authorizationHeader'
30
+ )
31
+ return masked
26
32
  }
27
33
 
28
34
  save(projectKey: string, resource: Project) {
@@ -56,6 +56,17 @@ describe('Product Projection', () => {
56
56
  })
57
57
  })
58
58
 
59
+ test('Get product projection by 404 when not found by key with expand', async () => {
60
+ const response = await supertest(ctMock.app).get(
61
+ '/dummy/product-projections/key=DOESNOTEXIST?' +
62
+ qs.stringify({
63
+ expand: ['categories[*]'],
64
+ })
65
+ )
66
+
67
+ expect(response.status).toBe(404)
68
+ })
69
+
59
70
  test('Search product projection', async () => {
60
71
  ctMock.project('dummy').add('product-projection', {
61
72
  id: '',
package/src/storage.ts CHANGED
@@ -211,8 +211,14 @@ export class InMemoryStorage extends AbstractStorage {
211
211
 
212
212
  const resources: any[] = Array.from(store.values())
213
213
  const resource = resources.find(e => e.key === key)
214
- if (params.expand) return this.expand(projectKey, resource, params.expand)
215
- return resource
214
+ if (resource) {
215
+ return this.expand(
216
+ projectKey,
217
+ resource,
218
+ params.expand
219
+ ) as ResourceMap[RepositoryTypes]
220
+ }
221
+ return null
216
222
  }
217
223
 
218
224
  delete(