@toa.io/extensions.origins 0.10.0-dev.13 → 0.10.0-dev.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/extensions.origins",
3
- "version": "0.10.0-dev.13",
3
+ "version": "0.10.0-dev.15",
4
4
  "description": "Toa Origins",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,15 +19,15 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
- "@toa.io/core": "1.1.0-dev.13",
23
- "@toa.io/generic": "0.11.0-dev.13",
24
- "@toa.io/schemas": "0.8.4-dev.13",
25
- "@toa.io/yaml": "0.7.6-dev.13",
22
+ "@toa.io/core": "1.1.0-dev.15",
23
+ "@toa.io/generic": "0.11.0-dev.15",
24
+ "@toa.io/schemas": "0.8.4-dev.15",
25
+ "@toa.io/yaml": "0.7.6-dev.15",
26
26
  "comq": "0.7.0",
27
27
  "node-fetch": "2.6.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node-fetch": "2.6.2"
31
31
  },
32
- "gitHead": "8c824ed7448e01f0ddf44500a4a6e692d35eaa1b"
32
+ "gitHead": "f479f6e79d5caaa207da4d0a3192425def1abf75"
33
33
  }
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @param {string} reference
5
+ */
6
+ function check (reference) {
7
+ if (typeof reference !== 'string') return // aspect properties object
8
+
9
+ const url = new URL(reference)
10
+
11
+ if (url.username !== '' || url.password !== '') throw new Error('Origins must not contain credentials. Please use environment secrets instead.')
12
+ }
13
+
14
+ exports.check = check
@@ -4,6 +4,7 @@ const { merge } = require('@toa.io/generic')
4
4
  const schemas = require('./schemas')
5
5
  const protocols = require('./protocols')
6
6
  const create = require('./.deployment')
7
+ const credentials = require('./.credentials')
7
8
 
8
9
  /**
9
10
  * @param {toa.norm.context.dependencies.Instance[]} instances
@@ -11,7 +12,7 @@ const create = require('./.deployment')
11
12
  * @returns {toa.deployment.dependency.Declaration}
12
13
  */
13
14
  function deployment (instances, annotations = {}) {
14
- schemas.annotations.validate(annotations)
15
+ validate(annotations)
15
16
 
16
17
  const uris = create.uris(instances, annotations)
17
18
  const variables = { ...uris }
@@ -25,4 +26,16 @@ function deployment (instances, annotations = {}) {
25
26
  return { variables }
26
27
  }
27
28
 
29
+ /**
30
+ * @param {toa.origins.Annotations} annotations
31
+ * @return {void}
32
+ */
33
+ function validate (annotations) {
34
+ schemas.annotations.validate(annotations)
35
+
36
+ for (const component of Object.values(annotations)) {
37
+ Object.values(component).forEach(credentials.check)
38
+ }
39
+ }
40
+
28
41
  exports.deployment = deployment
@@ -100,6 +100,18 @@ it('should create variables', () => {
100
100
  expect(variable.value).toStrictEqual(base64)
101
101
  })
102
102
 
103
+ it.each(['http', 'amqp'])('should throw if %s annotation contains credentials',
104
+ async (protocol) => {
105
+ /** @type {toa.origins.Annotations} */
106
+ const annotations = {
107
+ [component.locator.id]: {
108
+ [origin]: protocol + '://dev:sec@host-' + generate()
109
+ }
110
+ }
111
+
112
+ expect(() => deployment(components, annotations)).toThrow('Origins must not contain credentials')
113
+ })
114
+
103
115
  describe('amqp', () => {
104
116
  beforeEach(() => {
105
117
  const amqpComponents = components.filter(
@@ -3,6 +3,7 @@
3
3
  const { remap, echo, shards } = require('@toa.io/generic')
4
4
  const schemas = require('./schemas')
5
5
  const protocols = require('./protocols')
6
+ const credentials = require('./.credentials')
6
7
 
7
8
  /**
8
9
  * @param {toa.origins.Manifest} manifest
@@ -29,6 +30,8 @@ function manifest (manifest) {
29
30
  function validate (manifest) {
30
31
  manifest = remap(manifest, (value) => shards(value)[0])
31
32
  schemas.manifest.validate(manifest)
33
+
34
+ Object.values(manifest).forEach(credentials.check)
32
35
  }
33
36
 
34
37
  function supports (provider, url) {
@@ -73,3 +73,10 @@ it('should handle port shards', async () => {
73
73
 
74
74
  expect(() => manifest(input)).not.toThrow()
75
75
  })
76
+
77
+ it.each(['dev:sec', 'dev'])('should throw if url contains credentials (%s)',
78
+ async (credentials) => {
79
+ const input = { foo: `http://${credentials}@${generate()}:888{0-9}` }
80
+
81
+ expect(() => manifest(input)).toThrow('must not contain credentials')
82
+ })