scooter 0.0.0 → 3.2.19
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.
- checksums.yaml +15 -0
- data/.env +5 -0
- data/.gitignore +47 -19
- data/Gemfile +3 -0
- data/HISTORY.md +1539 -0
- data/README.md +69 -10
- data/Rakefile +7 -0
- data/docs/http_dispatchers.md +79 -0
- data/lib/scooter.rb +11 -3
- data/lib/scooter/httpdispatchers.rb +12 -0
- data/lib/scooter/httpdispatchers/activity.rb +46 -0
- data/lib/scooter/httpdispatchers/activity/v1/v1.rb +50 -0
- data/lib/scooter/httpdispatchers/classifier.rb +376 -0
- data/lib/scooter/httpdispatchers/classifier/v1/v1.rb +99 -0
- data/lib/scooter/httpdispatchers/code_manager.rb +31 -0
- data/lib/scooter/httpdispatchers/code_manager/v1/v1.rb +17 -0
- data/lib/scooter/httpdispatchers/consoledispatcher.rb +132 -0
- data/lib/scooter/httpdispatchers/httpdispatcher.rb +168 -0
- data/lib/scooter/httpdispatchers/orchestrator/v1/v1.rb +87 -0
- data/lib/scooter/httpdispatchers/orchestratordispatcher.rb +83 -0
- data/lib/scooter/httpdispatchers/puppetdb/v4/v4.rb +51 -0
- data/lib/scooter/httpdispatchers/puppetdbdispatcher.rb +390 -0
- data/lib/scooter/httpdispatchers/rbac.rb +231 -0
- data/lib/scooter/httpdispatchers/rbac/v1/directory_service.rb +68 -0
- data/lib/scooter/httpdispatchers/rbac/v1/v1.rb +116 -0
- data/lib/scooter/ldap.rb +349 -0
- data/lib/scooter/ldap/ldap_fixtures.rb +60 -0
- data/lib/scooter/middleware/rbac_auth_token.rb +35 -0
- data/lib/scooter/utilities.rb +9 -0
- data/lib/scooter/utilities/beaker_utilities.rb +41 -0
- data/lib/scooter/utilities/string_utilities.rb +32 -0
- data/lib/scooter/version.rb +3 -1
- data/scooter.gemspec +23 -6
- data/spec/scooter/beaker_utilities_spec.rb +53 -0
- data/spec/scooter/httpdispatchers/activity/activity_spec.rb +218 -0
- data/spec/scooter/httpdispatchers/classifier/classifier_spec.rb +542 -0
- data/spec/scooter/httpdispatchers/code_manager/code-manager_spec.rb +67 -0
- data/spec/scooter/httpdispatchers/consoledispatcher_spec.rb +80 -0
- data/spec/scooter/httpdispatchers/httpdispatcher_spec.rb +91 -0
- data/spec/scooter/httpdispatchers/middleware/rbac_auth_token_spec.rb +58 -0
- data/spec/scooter/httpdispatchers/orchestratordispatcher_spec.rb +195 -0
- data/spec/scooter/httpdispatchers/puppetdbdispatcher_spec.rb +246 -0
- data/spec/scooter/httpdispatchers/rbac/rbac_spec.rb +387 -0
- data/spec/scooter/string_utilities_spec.rb +83 -0
- data/spec/spec_helper.rb +8 -0
- metadata +270 -18
- data/LICENSE.txt +0 -15
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Scooter
|
|
2
|
+
module LDAP
|
|
3
|
+
class LDAPFixtures
|
|
4
|
+
attr_reader :users
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def self.users(test_uid=nil)
|
|
8
|
+
{ 'howard' =>
|
|
9
|
+
{ :cn => "howard#{test_uid}",
|
|
10
|
+
:sn => "lovecraft",
|
|
11
|
+
:displayName => "Howard P. Lovecraft#{test_uid}",
|
|
12
|
+
:mail => "howard@example.com"
|
|
13
|
+
},
|
|
14
|
+
'sylvia' =>
|
|
15
|
+
{ :cn => "sylvia#{test_uid}",
|
|
16
|
+
:sn => "plath",
|
|
17
|
+
:displayName => "Sylvia Plath#{test_uid}",
|
|
18
|
+
:mail => "sylvia@example.com"
|
|
19
|
+
},
|
|
20
|
+
'guillermo' =>
|
|
21
|
+
{ :cn => "guillermo#{test_uid}",
|
|
22
|
+
:sn => "del toro",
|
|
23
|
+
:displayName => "Guillermo del Toro#{test_uid}",
|
|
24
|
+
:mail => "guillermo@example.com"
|
|
25
|
+
},
|
|
26
|
+
'jorge' =>
|
|
27
|
+
{ :cn => "jorge#{test_uid}",
|
|
28
|
+
:sn => "borges",
|
|
29
|
+
:displayName => "Jorge Borges#{test_uid}",
|
|
30
|
+
:mail => "jorge@example.com"
|
|
31
|
+
},
|
|
32
|
+
'arthur' =>
|
|
33
|
+
{ :cn => "arthur#{test_uid}",
|
|
34
|
+
:sn => "doyle",
|
|
35
|
+
:displayName => "Sir Arthur Conan Doyle#{test_uid}",
|
|
36
|
+
:mail => "arthur@example.com"
|
|
37
|
+
},
|
|
38
|
+
'oscar' =>
|
|
39
|
+
{ :cn => "oscar#{test_uid}",
|
|
40
|
+
:sn => 'wilde',
|
|
41
|
+
:displayName => "Oscar Fingal O'Flahertie Wills Wilde#{test_uid}",
|
|
42
|
+
:mail => 'oscar@example.com'
|
|
43
|
+
},
|
|
44
|
+
'stephen' =>
|
|
45
|
+
{ :cn => "stephen#{test_uid}",
|
|
46
|
+
:sn => 'sondheim',
|
|
47
|
+
:displayName => "Stephen Sondheim#{test_uid}",
|
|
48
|
+
:mail => 'stephen@example.com'
|
|
49
|
+
},
|
|
50
|
+
'tony' =>
|
|
51
|
+
{ :cn => "tony#{test_uid}",
|
|
52
|
+
:sn => "stark",
|
|
53
|
+
:displayName => "Tony Stark#{test_uid}",
|
|
54
|
+
:mail => "tony@example.com"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Faraday
|
|
2
|
+
# This middleware checks for tokens and adds them to the request when found.
|
|
3
|
+
# To include this correctly, you will need to pass the dispatcher itself to
|
|
4
|
+
# the initialize method so it can read if the dispatcher has tokens or not.
|
|
5
|
+
# Beyond just the token itself, it also checks the dispatcher if the
|
|
6
|
+
# instance variable <i>send_auth_token_as_query_param</i> is set to true.
|
|
7
|
+
# Otherwise, it will always attach it as an X-Authentication header.
|
|
8
|
+
class RbacAuthToken < Faraday::Middleware
|
|
9
|
+
attr_reader :dispatcher
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# @param app() Structural requirement for Faraday::Middleware initialization
|
|
13
|
+
# @param dispatcher(Scooter::HttpDispatchers::ConsoleDispatcher required)
|
|
14
|
+
# Required param so that the middleware can check to see if there is a
|
|
15
|
+
# token set in the implementing dispatcher class. Will work with
|
|
16
|
+
# <i>ConsoleDispatcher</i>.
|
|
17
|
+
def initialize(app, dispatcher)
|
|
18
|
+
super(app)
|
|
19
|
+
@dispatcher = dispatcher
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def call(env)
|
|
23
|
+
if dispatcher.token && dispatcher.send_auth_token_as_query_param
|
|
24
|
+
query_array = [['token', dispatcher.token]]
|
|
25
|
+
URI.decode_www_form(env.url.query).each {|tuple| query_array << tuple} if env.url.query
|
|
26
|
+
env.url.query = URI.encode_www_form(query_array)
|
|
27
|
+
elsif dispatcher.token
|
|
28
|
+
env.request_headers['X-Authentication'] = dispatcher.token
|
|
29
|
+
end
|
|
30
|
+
@app.call env
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Faraday::Request.register_middleware :rbac_auth_token => lambda { Faraday::RbacAuthToken }
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Scooter
|
|
2
|
+
module Utilities
|
|
3
|
+
module BeakerUtilities
|
|
4
|
+
extend Beaker::DSL
|
|
5
|
+
|
|
6
|
+
# Beaker and ec2 don't play nice with getting the public ip. It is only set during
|
|
7
|
+
# initial provision and can be over-ridden. If you also have to run the script several times,
|
|
8
|
+
# or are using an existing set of nodes for testing, beaker has no way to get the
|
|
9
|
+
# ec2 instanes public ip address, mostly because the box it self does not expose it anywhere.
|
|
10
|
+
# According to the docs, you can curl the below to get it
|
|
11
|
+
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
|
|
12
|
+
def self.get_public_ip(host)
|
|
13
|
+
if host['hypervisor'] == 'ec2'
|
|
14
|
+
on(host, "curl http://169.254.169.254/latest/meta-data/public-ipv4").stdout
|
|
15
|
+
else
|
|
16
|
+
host.ip
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.pe_ca_cert_file(master)
|
|
21
|
+
ca_cert = on(master, "cat `puppet agent --configprint localcacert`", :silent => true).stdout
|
|
22
|
+
|
|
23
|
+
cert_dir = Dir.mktmpdir("pe_certs")
|
|
24
|
+
|
|
25
|
+
ca_cert_file = File.join(cert_dir, "cacert.pem")
|
|
26
|
+
File.open(ca_cert_file, "w+") do |f|
|
|
27
|
+
f.write(ca_cert)
|
|
28
|
+
end
|
|
29
|
+
ca_cert_file
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.pe_private_key(master)
|
|
33
|
+
on(master, "cat `puppet agent --configprint hostprivkey`", :silent => true).stdout
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.pe_hostcert(master)
|
|
37
|
+
on(master, "cat `puppet agent --configprint hostcert`", :silent => true).stdout
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Scooter
|
|
2
|
+
module Utilities
|
|
3
|
+
module StringUtilities
|
|
4
|
+
|
|
5
|
+
class RandomString
|
|
6
|
+
def self.generate(length = 32)
|
|
7
|
+
characters = [('0'..'9'), ('a'..'z'), ('A'..'Z')]
|
|
8
|
+
characters = characters.map{ |i| i.to_a }.flatten
|
|
9
|
+
(0...length).map{ characters[rand(characters.length)] }.join
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Create a string of two-byte Cyrillic characters.
|
|
14
|
+
class RandomTwoByteUnicodeString
|
|
15
|
+
def self.generate(length = 32)
|
|
16
|
+
characters = (0x0400..0x04FF).to_a.map {|e| e.chr(Encoding::UTF_8) }
|
|
17
|
+
(0...length).map{ characters[rand(characters.length)] }.join
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create some single-byte characters outside the ASCII 7-bit range.
|
|
22
|
+
class RandomHighbitString
|
|
23
|
+
def self.generate(length = 32)
|
|
24
|
+
characters = (0x80..0xFF).to_a.map {|e| e.chr }
|
|
25
|
+
(0...length).map{ characters[rand(characters.length)] }.join
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
data/lib/scooter/version.rb
CHANGED
data/scooter.gemspec
CHANGED
|
@@ -5,19 +5,36 @@ require 'scooter/version'
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "scooter"
|
|
8
|
-
spec.version = Scooter::
|
|
8
|
+
spec.version = Scooter::Version::STRING
|
|
9
9
|
spec.authors = ["Puppetlabs"]
|
|
10
10
|
spec.email = ["qa@puppetlabs.com"]
|
|
11
11
|
spec.summary = %q{Puppetlabs testing tool}
|
|
12
|
-
spec.description = %q{Puppetlabs testing tool}
|
|
13
|
-
spec.homepage = ""
|
|
14
|
-
spec.license = "Apache2"
|
|
12
|
+
spec.description = %q{Puppetlabs testing tool coupled with Beaker}
|
|
13
|
+
spec.homepage = "https://github.com/puppetlabs/scooter"
|
|
15
14
|
|
|
16
15
|
spec.files = `git ls-files -z`.split("\x0")
|
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
18
|
spec.require_paths = ["lib"]
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
spec.add_development_dependency
|
|
20
|
+
#Development dependencies
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
22
|
+
spec.add_development_dependency 'pry', '~> 0.9.12'
|
|
23
|
+
spec.add_development_dependency 'rake'
|
|
24
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
|
25
|
+
|
|
26
|
+
#Documentation dependencies
|
|
27
|
+
spec.add_development_dependency 'yard', '~> 0'
|
|
28
|
+
spec.add_development_dependency 'markdown', '~> 0'
|
|
29
|
+
spec.add_development_dependency 'activesupport', '4.2.6'
|
|
30
|
+
|
|
31
|
+
#Run time dependencies
|
|
32
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
|
33
|
+
spec.add_runtime_dependency 'test-unit'
|
|
34
|
+
spec.add_runtime_dependency 'net-ldap', '~> 0.6', '>= 0.6.1', '<= 0.12.1'
|
|
35
|
+
spec.add_runtime_dependency 'beaker', '>= 2.1.0'
|
|
36
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.1'
|
|
37
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
|
|
38
|
+
spec.add_runtime_dependency 'faraday-cookie_jar', '~> 0.0', '>= 0.0.6'
|
|
39
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.5', '>= 1.5.10'
|
|
23
40
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Scooter
|
|
4
|
+
|
|
5
|
+
describe Utilities::BeakerUtilities do
|
|
6
|
+
|
|
7
|
+
let(:result) { instance_double(Beaker::Result)}
|
|
8
|
+
let(:master) { instance_double(Beaker::Host) }
|
|
9
|
+
|
|
10
|
+
context 'with correct argument' do
|
|
11
|
+
|
|
12
|
+
it 'gets the pe ca certfile' do
|
|
13
|
+
cmd = "cat `puppet agent --configprint localcacert`"
|
|
14
|
+
expect_any_instance_of(Beaker::DSL).to receive(:on).with(master, cmd, any_args).and_return(result)
|
|
15
|
+
expect(result).to receive(:stdout).and_return('foobar')
|
|
16
|
+
expect(subject.pe_ca_cert_file(master)).to match(/\/.*pe_certs.*\/cacert.pem/)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'gets the pe hostprivkey' do
|
|
20
|
+
cmd = "cat `puppet agent --configprint hostprivkey`"
|
|
21
|
+
expect_any_instance_of(Beaker::DSL).to receive(:on).with(master, cmd, any_args).and_return(result)
|
|
22
|
+
expect(result).to receive(:stdout).and_return('foobar')
|
|
23
|
+
expect(subject.pe_private_key(master)).to eq('foobar')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'gets the pe hostcert' do
|
|
27
|
+
cmd = "cat `puppet agent --configprint hostcert`"
|
|
28
|
+
expect_any_instance_of(Beaker::DSL).to receive(:on).with(master, cmd, any_args).and_return(result)
|
|
29
|
+
expect(result).to receive(:stdout).and_return('foobar')
|
|
30
|
+
expect(subject.pe_hostcert(master)).to eq('foobar')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'without correct arguments' do
|
|
36
|
+
|
|
37
|
+
it 'getting the pe ca certificate fails with no arguments' do
|
|
38
|
+
expect{ subject.pe_ca_cert_file }.to raise_error(ArgumentError)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'getting the pe hostprivkey fails with no arguments' do
|
|
42
|
+
expect{ subject.pe_private_key }.to raise_error(ArgumentError)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'getting the pe hostcert fails with no arguments' do
|
|
46
|
+
expect{ subject.pe_hostcert }.to raise_error(ArgumentError)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Scooter
|
|
4
|
+
|
|
5
|
+
describe Scooter::HttpDispatchers::Activity do
|
|
6
|
+
|
|
7
|
+
let(:host) { double('host') }
|
|
8
|
+
let(:credentials) { double('credentials') }
|
|
9
|
+
let(:classifier_events) {
|
|
10
|
+
{
|
|
11
|
+
"commits" => [
|
|
12
|
+
{
|
|
13
|
+
"object" => {
|
|
14
|
+
"id" => "da180809-36b1-4049-ab7b-29188dd6e255",
|
|
15
|
+
"name" => "Agent-specified environment"
|
|
16
|
+
},
|
|
17
|
+
"subject" => {
|
|
18
|
+
"id" => "af94921f-bd76-4b58-b5ce-e17c029a2790",
|
|
19
|
+
"name" => "api_user"
|
|
20
|
+
},
|
|
21
|
+
"timestamp" => "2016-06-09T18:08:13Z",
|
|
22
|
+
"events" => [
|
|
23
|
+
{
|
|
24
|
+
"message" => "Changed the environment override setting to true"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"message" => "Changed the environment to \"agent-specified\""
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"message" => "Changed the parent to 395ad98e-c536-4dfc-9f5f-b00d5ee2454f"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"message" => "Created the \"Agent-specified environment\" group with id da180809-36b1-4049-ab7b-29188dd6e255"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"object" => {
|
|
39
|
+
"id" => "395ad98e-c536-4dfc-9f5f-b00d5ee2454f",
|
|
40
|
+
"name" => "Production environment"
|
|
41
|
+
},
|
|
42
|
+
"subject" => {
|
|
43
|
+
"id" => "af94921f-bd76-4b58-b5ce-e17c029a2790",
|
|
44
|
+
"name" => "api_user"
|
|
45
|
+
},
|
|
46
|
+
"timestamp" => "2016-06-09T18:08:13Z",
|
|
47
|
+
"events" => [
|
|
48
|
+
{
|
|
49
|
+
"message" => "Changed the environment override setting to true"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"message" => "Changed the environment to \"production\""
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"message" => "Changed the parent to 00000000-0000-4000-8000-000000000000"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"message" => "Changed the rule to [\"and\" [\"~\" \"name\" \".*\"]]"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"message" => "Created the \"Production environment\" group with id 395ad98e-c536-4dfc-9f5f-b00d5ee2454f"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let(:rbac_events) {
|
|
69
|
+
{
|
|
70
|
+
"commits" => [
|
|
71
|
+
{
|
|
72
|
+
"object" => {
|
|
73
|
+
"id" => "42bf351c-f9ec-40af-84ad-e976fec7f4bd",
|
|
74
|
+
"name" => "admin"
|
|
75
|
+
},
|
|
76
|
+
"subject" => {
|
|
77
|
+
"id" => "42bf351c-f9ec-40af-84ad-e976fec7f4bd",
|
|
78
|
+
"name" => "admin"
|
|
79
|
+
},
|
|
80
|
+
"timestamp" => "2016-06-09T19:14:26Z",
|
|
81
|
+
"events" => [
|
|
82
|
+
{
|
|
83
|
+
"message" => "User Administrator (42bf351c-f9ec-40af-84ad-e976fec7f4bd) logged in."
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"object" => {
|
|
89
|
+
"id" => "42bf351c-f9ec-40af-84ad-e976fec7f4bd",
|
|
90
|
+
"name" => "admin"
|
|
91
|
+
},
|
|
92
|
+
"subject" => {
|
|
93
|
+
"id" => "42bf351c-f9ec-40af-84ad-e976fec7f4bd",
|
|
94
|
+
"name" => "admin"
|
|
95
|
+
},
|
|
96
|
+
"timestamp" => "2016-06-09T18:08:14Z",
|
|
97
|
+
"events" => [
|
|
98
|
+
{
|
|
99
|
+
"message" => "Password reset for user Administrator (42bf351c-f9ec-40af-84ad-e976fec7f4bd)."
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"object" => {
|
|
105
|
+
"id" => "42bf351c-f9ec-40af-84ad-e976fec7f4bd",
|
|
106
|
+
"name" => "admin"
|
|
107
|
+
},
|
|
108
|
+
"subject" => {
|
|
109
|
+
"id" => "af94921f-bd76-4b58-b5ce-e17c029a2790",
|
|
110
|
+
"name" => "api_user"
|
|
111
|
+
},
|
|
112
|
+
"timestamp" => "2016-06-09T18:08:14Z",
|
|
113
|
+
"events" => [
|
|
114
|
+
{
|
|
115
|
+
"message" => "A password reset token was generated for user Administrator (42bf351c-f9ec-40af-84ad-e976fec7f4bd)."
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"offset" => 0,
|
|
121
|
+
"limit" => 3,
|
|
122
|
+
"total-rows" => 3
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
subject { HttpDispatchers::ConsoleDispatcher.new(host, credentials) }
|
|
127
|
+
|
|
128
|
+
context 'with a beaker host passed in' do
|
|
129
|
+
|
|
130
|
+
unixhost = { roles: ['test_role'],
|
|
131
|
+
'platform' => 'debian-7-x86_64' }
|
|
132
|
+
let(:host) { Beaker::Host.create('test.com', unixhost, {}) }
|
|
133
|
+
let(:credentials) { { login: 'Ziggy', password: 'Stardust' } }
|
|
134
|
+
|
|
135
|
+
before do
|
|
136
|
+
expect(Scooter::Utilities::BeakerUtilities).to receive(:pe_ca_cert_file).and_return('cert file')
|
|
137
|
+
expect(Scooter::Utilities::BeakerUtilities).to receive(:get_public_ip).and_return('public_ip')
|
|
138
|
+
expect(subject).not_to be_nil
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe '.get_classifier_events' do
|
|
142
|
+
before do
|
|
143
|
+
# find the index of the default Faraday::Adapter::NetHttp handler
|
|
144
|
+
# and replace it with the Test adapter
|
|
145
|
+
index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
|
|
146
|
+
subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
|
|
147
|
+
stub.get('activity-api/v1/events?service_id=classifier') { [200, {}] }
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
it 'gets classifier events' do
|
|
151
|
+
expect { subject.get_classifier_events }.not_to raise_error
|
|
152
|
+
response = subject.get_classifier_events
|
|
153
|
+
expect(response.status).to eq(200)
|
|
154
|
+
hashed_query = CGI.parse(response.env.url.query)
|
|
155
|
+
expect(hashed_query).to eq('service_id' => ['classifier'])
|
|
156
|
+
end
|
|
157
|
+
it 'appends additional query string parameters' do
|
|
158
|
+
expect { subject.get_classifier_events }.not_to raise_error
|
|
159
|
+
response = subject.get_classifier_events({ 'subject_type' => 'users', 'subject_id' => 'dfgdfc145-545dfg54f-fdg45s5s' })
|
|
160
|
+
hashed_query = CGI.parse(response.env.url.query)
|
|
161
|
+
expect(hashed_query).to eq({ 'service_id' => ['classifier'], 'subject_type' => ['users'], 'subject_id' => ['dfgdfc145-545dfg54f-fdg45s5s'] })
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe '.get_rbac_events' do
|
|
166
|
+
before do
|
|
167
|
+
# find the index of the default Faraday::Adapter::NetHttp handler
|
|
168
|
+
# and replace it with the Test adapter
|
|
169
|
+
index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
|
|
170
|
+
subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
|
|
171
|
+
stub.get('activity-api/v1/events?service_id=rbac') { [200, {}] }
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
it 'gets rbac events' do
|
|
175
|
+
expect { subject.get_rbac_events }.not_to raise_error
|
|
176
|
+
response = subject.get_rbac_events
|
|
177
|
+
expect(response.status).to eq(200)
|
|
178
|
+
hashed_query = CGI.parse(response.env.url.query)
|
|
179
|
+
expect(hashed_query).to eq('service_id' => ['rbac'])
|
|
180
|
+
end
|
|
181
|
+
it 'appends additional query string parameters' do
|
|
182
|
+
expect { subject.get_rbac_events }.not_to raise_error
|
|
183
|
+
response = subject.get_rbac_events({ 'subject_type' => 'users', 'subject_id' => 'dfgdfc145-545dfg54f-fdg45s5s' })
|
|
184
|
+
expect(response.status).to eq(200)
|
|
185
|
+
hashed_query = CGI.parse(response.env.url.query)
|
|
186
|
+
expect(hashed_query).to eq({ 'service_id' => ['rbac'], 'subject_type' => ['users'], 'subject_id' => ['dfgdfc145-545dfg54f-fdg45s5s'] })
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '.activity_database_matches_self?' do
|
|
191
|
+
before do
|
|
192
|
+
# find the index of the default Faraday::Adapter::NetHttp handler
|
|
193
|
+
# and replace it with the Test adapter
|
|
194
|
+
index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
|
|
195
|
+
subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
|
|
196
|
+
stub.get('activity-api/v1/events?service_id=rbac') { |env| env[:url].to_s == "https://test.com:4433/activity-api/v1/events?service_id=rbac" ?
|
|
197
|
+
[200, [], rbac_events] :
|
|
198
|
+
[200, [], rbac_events.dup["commits"].push('another_array_item')] }
|
|
199
|
+
stub.get('activity-api/v1/events?service_id=classifier') { |env| env[:url].to_s == "https://test.com:4433/activity-api/v1/events?service_id=classifier" ?
|
|
200
|
+
[200, [], classifier_events] :
|
|
201
|
+
[200, [], classifier_events.dup["commits"].push('another_array_item')] }
|
|
202
|
+
end
|
|
203
|
+
expect(subject).to receive(:create_default_connection).with(any_args).twice.and_return(subject.connection)
|
|
204
|
+
expect(Scooter::Utilities::BeakerUtilities).to receive(:get_public_ip).and_return('public_ip')
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'compare with self' do
|
|
208
|
+
expect(subject.activity_database_matches_self?('test.com')).to be_truthy
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'compare with different' do
|
|
212
|
+
expect(subject.faraday_logger).to receive(:warn).with /Rbac events do not match/
|
|
213
|
+
expect(subject.activity_database_matches_self?('test2.com')).to be_falsey
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|