umts-microservices-engine 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/microservices_engine/v1/data_controller.rb +2 -1
- data/lib/generators/install/templates/microservices_engine.rb +1 -1
- data/lib/microservices_engine.rb +3 -3
- data/lib/microservices_engine/version.rb +1 -1
- data/spec/controllers/data_controller_spec.rb +13 -41
- data/spec/microservices_engine_spec.rb +91 -2
- data/spec/models/connection_spec.rb +4 -4
- data/spec/mse_spec_helper.rb +70 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c498cd845409f6ef09e95e9df99569b269928fb
|
4
|
+
data.tar.gz: b37e6e9fd532670afe1a109a9e1ffa393a5575f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ca82abc02906755a30b917bfcb7e2d7ba05b6e6616468ebae4af214c225fea9e14e583e9b15f32925b8f1059e3ab9a67a3c551e209faece9a1ff5538ab1fd8
|
7
|
+
data.tar.gz: c914a8d387381250d298cfce6a31478373cf5e15f110c0b3a978bb1190899a781d817e502c4be7056a1d409614d73c0174a6c7cc91ec1bc16a6637583a33c60d
|
@@ -31,7 +31,8 @@ module MicroservicesEngine
|
|
31
31
|
data = params['content']
|
32
32
|
data_objects = data.map { |d| d['object'] }
|
33
33
|
|
34
|
-
|
34
|
+
# Disabled until router implements token authorization
|
35
|
+
# verify_token(params['token'])
|
35
36
|
verify_build(params['build'])
|
36
37
|
|
37
38
|
existing = Connection.all
|
@@ -13,7 +13,7 @@ if [config_data['name'], config_data['uri'], config_data['security_token']].any?
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Make sure the URI ends with a / character
|
16
|
-
router_uri =
|
16
|
+
router_uri = config_data['router_uri']
|
17
17
|
|
18
18
|
uri = config_data['uri']
|
19
19
|
uri += '/' if uri[-1] != '/'
|
data/lib/microservices_engine.rb
CHANGED
@@ -30,12 +30,12 @@ module MicroservicesEngine
|
|
30
30
|
# ------------------------------------------------------ #
|
31
31
|
invalid_changes = [
|
32
32
|
cmajor > major,
|
33
|
-
cminor > minor &&
|
34
|
-
crev > rev && cminor
|
33
|
+
cminor > minor && !(major > cmajor),
|
34
|
+
crev > rev && !(minor > cminor || major > cmajor)
|
35
35
|
]
|
36
36
|
|
37
37
|
if invalid_changes.any?
|
38
|
-
raise
|
38
|
+
raise "Received version is older than existing. Now: #{build}. Given: #{b}"
|
39
39
|
end
|
40
40
|
|
41
41
|
@build = b
|
@@ -1,15 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'rails_helper'
|
3
|
-
|
4
|
-
# PLANNED FOR MOVE TO OTHER FILE
|
5
|
-
def change_build(v, b)
|
6
|
-
b['build'] = v
|
7
|
-
end
|
8
|
-
|
9
|
-
def relative_build(ma, mi, r)
|
10
|
-
[ma, mi, r].map { |ver| 1 + ver }.join('.')
|
11
|
-
end
|
12
|
-
# PLANNED FOR MOVE TO OTHER FILE
|
3
|
+
require 'mse_spec_helper'
|
13
4
|
|
14
5
|
describe MicroservicesEngine::V1::DataController, type: :controller do
|
15
6
|
routes { MicroservicesEngine::Engine.routes }
|
@@ -19,22 +10,7 @@ describe MicroservicesEngine::V1::DataController, type: :controller do
|
|
19
10
|
|
20
11
|
before(:each) do
|
21
12
|
MicroservicesEngine.build = '1.1.1'
|
22
|
-
@data =
|
23
|
-
'build': '1.1.2',
|
24
|
-
'token': 'TEST_ENV_VALID_TOKEN',
|
25
|
-
'content': [
|
26
|
-
{
|
27
|
-
'name': 'Endpoint 1',
|
28
|
-
'object': 'FieldTrip',
|
29
|
-
'url': 'http://example.com/microservices_engine/v1/data'
|
30
|
-
},
|
31
|
-
{
|
32
|
-
'name': 'Endpoint 2',
|
33
|
-
'object': 'Survey',
|
34
|
-
'url': 'http://potatoes.com/microservices_engine/v1/data'
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
13
|
+
@data = build_basic_data
|
38
14
|
@changed_data = @data.deep_dup # A version of data that is changed for tests
|
39
15
|
end
|
40
16
|
|
@@ -52,23 +28,21 @@ describe MicroservicesEngine::V1::DataController, type: :controller do
|
|
52
28
|
expect { process :register, method: :post, params: @data }.not_to raise_error
|
53
29
|
end
|
54
30
|
|
55
|
-
|
56
|
-
|
57
|
-
|
31
|
+
# This test is disabled until the router implements the appropriate logic
|
32
|
+
# it 'denies invalid token' do
|
33
|
+
# 1. Change base data to be an invalid token
|
34
|
+
# 2. Expect the request to cause an error.
|
58
35
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
36
|
+
# @changed_data['token'] = 'mayonnaise_is_not_an_instrument_patrick'
|
37
|
+
# expect { process :register, method: :post, params: @changed_data }.to raise_error(SecurityError)
|
38
|
+
# end
|
62
39
|
end
|
63
40
|
|
64
41
|
# The request updates the build version properly
|
65
42
|
describe 'updating MicroservicesEngine.build' do
|
66
43
|
context 'failing builds' do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
failing_builds.each do |failing_build|
|
71
|
-
it 'fails with older version #{failing_build}' do
|
44
|
+
failing_semantic_builds.each do |failing_build|
|
45
|
+
it "fails with older version #{failing_build}" do
|
72
46
|
change_build(failing_build, @changed_data)
|
73
47
|
expect { process :register, method: :post, params: @changed_data }.to raise_error(RuntimeError)
|
74
48
|
end
|
@@ -76,10 +50,8 @@ describe MicroservicesEngine::V1::DataController, type: :controller do
|
|
76
50
|
end
|
77
51
|
|
78
52
|
context 'passing builds' do
|
79
|
-
|
80
|
-
|
81
|
-
passing_builds.each do |passing_build|
|
82
|
-
it 'passes with newer version #{passing_build}' do
|
53
|
+
passing_semantic_builds.each do |passing_build|
|
54
|
+
it "passes with newer version #{passing_build}" do
|
83
55
|
change_build(passing_build, @changed_data)
|
84
56
|
expect(MicroservicesEngine.build).to eq('1.1.1')
|
85
57
|
process :register, method: :post, params: @changed_data
|
@@ -2,7 +2,96 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
class MicroservicesEngineTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
|
5
|
+
describe MicroservicesEngine do
|
6
|
+
before(:each) do
|
7
|
+
MicroservicesEngine.build = '1.1.1'
|
8
|
+
@expected = {
|
9
|
+
'name': '',
|
10
|
+
'uri': '',
|
11
|
+
'security_token': '',
|
12
|
+
'router_uri': '',
|
13
|
+
'accessible_models': ''
|
14
|
+
}
|
15
|
+
allow(MicroservicesEngine).to receive(:config).and_return(@expected)
|
16
|
+
allow(MicroservicesEngine).to receive(:reload_config).and_return(@expected)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'build= and build' do
|
20
|
+
context 'failing builds' do
|
21
|
+
failing_semantic_builds.each do |failing_build|
|
22
|
+
it "fails with older version #{failing_build}" do
|
23
|
+
expect { MicroservicesEngine.build = failing_build }.to raise_error(RuntimeError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'passing builds' do
|
29
|
+
passing_semantic_builds.each do |passing_build|
|
30
|
+
it "passes with newer version #{passing_build}" do
|
31
|
+
expect(MicroservicesEngine.build).to eq('1.1.1')
|
32
|
+
MicroservicesEngine.build = passing_build
|
33
|
+
expect(MicroservicesEngine.build).to eq(passing_build)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Because they are alias methods, both are tested at once
|
40
|
+
describe 'reload_config and config' do
|
41
|
+
# With this test, we can effectively only test
|
42
|
+
# one of the methods and actually be testing both
|
43
|
+
it 'does the same thing' do
|
44
|
+
expect(MicroservicesEngine.reload_config)
|
45
|
+
.to be(MicroservicesEngine.config)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'loads the config' do
|
49
|
+
expect(MicroservicesEngine.config)
|
50
|
+
.to eq(@expected)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'loads the new config' do
|
54
|
+
@expected['name'] = 'potatoes'
|
55
|
+
expect(MicroservicesEngine.config)
|
56
|
+
.to eq(@expected)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'valid_token?' do
|
61
|
+
context 'on test environment' do
|
62
|
+
it 'accepts valid token' do
|
63
|
+
expect(MicroservicesEngine.valid_token?('TEST_ENV_VALID_TOKEN'))
|
64
|
+
.to be(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'refuses invalid token' do
|
68
|
+
expect(MicroservicesEngine.valid_token?('POTATOES_ARE_INVALID'))
|
69
|
+
.to be(false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'not on test environment' do
|
74
|
+
before(:each) do
|
75
|
+
@expected['security_token'] = 'PROD_ENV_VALID_TOKEN'
|
76
|
+
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production'))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'raises an error with no token config' do
|
80
|
+
@expected['security_token'] = ''
|
81
|
+
expect { MicroservicesEngine.valid_token?(':thinking:') }
|
82
|
+
.to raise_error(RuntimeError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'accepts valid token' do
|
86
|
+
expect(MicroservicesEngine.valid_token?('PROD_ENV_VALID_TOKEN'))
|
87
|
+
.to be(true)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'refuses invalid token' do
|
91
|
+
expect(MicroservicesEngine.valid_token?('POTATOES_ARE_STILL_INVALID'))
|
92
|
+
.to be(false)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
7
96
|
end
|
8
97
|
end
|
@@ -20,9 +20,9 @@ describe MicroservicesEngine::Connection do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'self.get' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
it 'implies params' do
|
24
|
+
expect_only_instance_of(MicroservicesEngine::Connection).to receive(:get).with(@path, {})
|
25
|
+
MicroservicesEngine::Connection.get('ExampleModel', @path)
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# -- Changes that directly affect RSpec -- #
|
4
|
+
module RSpec
|
5
|
+
module Mocks
|
6
|
+
::RSpec::Mocks::ExampleMethods.class_exec do
|
7
|
+
def expect_only_instance_of(klass)
|
8
|
+
expect(klass.count).to be(1)
|
9
|
+
AnyInstanceExpectationTarget.new(klass)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
# ---------------------------------------- #
|
15
|
+
|
16
|
+
# Changes the build key of a request
|
17
|
+
# Params:
|
18
|
+
# +v+:: The value to change the key to
|
19
|
+
# +b+:: The build request to change
|
20
|
+
def change_build(v, b)
|
21
|
+
b['build'] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
# Takes in a series of semantic versions (major, minor, revision)
|
25
|
+
# changes and outputs a new semantic version based off of 1.1.1
|
26
|
+
# Params:
|
27
|
+
# +major+:: Change in major version
|
28
|
+
# +minor+:: Change in minor version
|
29
|
+
# +revision+:: Change in revision version
|
30
|
+
def relative_build(major, minor, revision)
|
31
|
+
# Example usage:
|
32
|
+
# relative_build(1, -1, 0) = 2.0.1
|
33
|
+
# relative_build(0, 0, 0) = 1.1.1
|
34
|
+
[major, minor, revision].map { |ver| 1 + ver }.join('.')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a basic set fo a build data for integration testing
|
38
|
+
def build_basic_data
|
39
|
+
{
|
40
|
+
'build': '1.1.2',
|
41
|
+
'token': 'TEST_ENV_VALID_TOKEN',
|
42
|
+
'content': [
|
43
|
+
{
|
44
|
+
'name': 'Endpoint 1',
|
45
|
+
'object': 'FieldTrip',
|
46
|
+
'url': 'http://example.com/microservices_engine/v1/data'
|
47
|
+
},
|
48
|
+
{
|
49
|
+
'name': 'Endpoint 2',
|
50
|
+
'object': 'Survey',
|
51
|
+
'url': 'http://potatoes.com/microservices_engine/v1/data'
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Gives a list of all changes to a semantic build that are invalid
|
58
|
+
def failing_semantic_builds
|
59
|
+
[0, -1]
|
60
|
+
.repeated_permutation(3)
|
61
|
+
.to_a.map { |bld| relative_build(*bld) } - ['1.1.1']
|
62
|
+
end
|
63
|
+
|
64
|
+
# Gives a list of all changes to a semantic build that are valid
|
65
|
+
def passing_semantic_builds
|
66
|
+
base = [0, 1]
|
67
|
+
.repeated_permutation(3)
|
68
|
+
.to_a.map { |bld| relative_build(*bld) }
|
69
|
+
base + ['2.0.0', '2.1.0', '2.0.1', '1.2.0']
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umts-microservices-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- UMass Transportation Services
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- spec/microservices_engine/install_generator_spec.rb.old
|
135
135
|
- spec/microservices_engine_spec.rb
|
136
136
|
- spec/models/connection_spec.rb
|
137
|
+
- spec/mse_spec_helper.rb
|
137
138
|
- spec/rails_helper.rb
|
138
139
|
- spec/spec_helper.rb
|
139
140
|
homepage: https://github.com/umts/microservices-engine
|
@@ -165,5 +166,6 @@ test_files:
|
|
165
166
|
- spec/microservices_engine/install_generator_spec.rb.old
|
166
167
|
- spec/microservices_engine_spec.rb
|
167
168
|
- spec/models/connection_spec.rb
|
169
|
+
- spec/mse_spec_helper.rb
|
168
170
|
- spec/rails_helper.rb
|
169
171
|
- spec/spec_helper.rb
|