wss_agent 18.10.2 → 18.10.3
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 +4 -4
- data/.gitignore +15 -15
- data/.rspec +2 -2
- data/.travis.yml +6 -6
- data/Gemfile +4 -4
- data/LICENSE.txt +201 -201
- data/README.md +88 -88
- data/Rakefile +8 -8
- data/bin/wss_agent +13 -13
- data/lib/config/custom_default.yml +5 -5
- data/lib/config/default.yml +14 -14
- data/lib/data/ca-certificates.crt +4049 -4049
- data/lib/wss_agent.rb +50 -50
- data/lib/wss_agent/cli.rb +56 -56
- data/lib/wss_agent/client.rb +108 -108
- data/lib/wss_agent/configure.rb +115 -115
- data/lib/wss_agent/gem_sha1.rb +73 -73
- data/lib/wss_agent/project.rb +39 -39
- data/lib/wss_agent/response.rb +57 -57
- data/lib/wss_agent/response_inventory.rb +28 -28
- data/lib/wss_agent/response_policies.rb +77 -77
- data/lib/wss_agent/specifications.rb +202 -202
- data/lib/wss_agent/version.rb +4 -4
- data/spec/fixtures/vcr_cassettes/WssAgent_CLI/update/when_not_found_token/should_display_error_message.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/response_should_be_success.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_response_json_data.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_message_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_status_of_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/response_should_be_success.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_response_json_data.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_message_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_status_of_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/response_should_be_success.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_response_json_data.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_message_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_status_of_response.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_check_policies/should_check_policies.yml +50 -50
- data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/should_update_list_gems_on_server.yml +50 -50
- data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/when_check_policies_is_true/and_check_policies_return_a_violation/should_not_update_inventory.yml +2984 -2984
- data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/when_check_policies_is_true/and_check_policies_returns_without_a_violation/should_update_inventory.yml +2984 -2984
- data/spec/spec_helper.rb +36 -36
- data/spec/support/exit_code_matches.rb +37 -37
- data/spec/wss_agent/cli_spec.rb +58 -58
- data/spec/wss_agent/client_spec.rb +151 -151
- data/spec/wss_agent/configure_spec.rb +180 -180
- data/spec/wss_agent/specifications_spec.rb +162 -162
- data/wss_agent.gemspec +38 -38
- metadata +3 -3
data/spec/spec_helper.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
Bundler.setup
|
3
|
-
require 'faraday'
|
4
|
-
require 'wss_agent'
|
5
|
-
require 'webmock/rspec'
|
6
|
-
require 'timecop'
|
7
|
-
|
8
|
-
require 'vcr'
|
9
|
-
require 'support/exit_code_matches'
|
10
|
-
|
11
|
-
VCR.configure do |config|
|
12
|
-
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
13
|
-
config.hook_into :webmock
|
14
|
-
config.configure_rspec_metadata!
|
15
|
-
config.allow_http_connections_when_no_cassette = false
|
16
|
-
end
|
17
|
-
|
18
|
-
RSpec.configure do |config|
|
19
|
-
|
20
|
-
config.expect_with :rspec do |c|
|
21
|
-
c.syntax = :expect
|
22
|
-
end
|
23
|
-
|
24
|
-
def capture(stream)
|
25
|
-
begin
|
26
|
-
stream = stream.to_s
|
27
|
-
eval "$#{stream} = StringIO.new"
|
28
|
-
yield
|
29
|
-
result = eval("$#{stream}").string
|
30
|
-
ensure
|
31
|
-
eval("$#{stream} = #{stream.upcase}")
|
32
|
-
end
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
require 'faraday'
|
4
|
+
require 'wss_agent'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'timecop'
|
7
|
+
|
8
|
+
require 'vcr'
|
9
|
+
require 'support/exit_code_matches'
|
10
|
+
|
11
|
+
VCR.configure do |config|
|
12
|
+
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
13
|
+
config.hook_into :webmock
|
14
|
+
config.configure_rspec_metadata!
|
15
|
+
config.allow_http_connections_when_no_cassette = false
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
|
20
|
+
config.expect_with :rspec do |c|
|
21
|
+
c.syntax = :expect
|
22
|
+
end
|
23
|
+
|
24
|
+
def capture(stream)
|
25
|
+
begin
|
26
|
+
stream = stream.to_s
|
27
|
+
eval "$#{stream} = StringIO.new"
|
28
|
+
yield
|
29
|
+
result = eval("$#{stream}").string
|
30
|
+
ensure
|
31
|
+
eval("$#{stream} = #{stream.upcase}")
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
RSpec::Matchers.define :terminate do |code|
|
2
|
-
actual = nil
|
3
|
-
|
4
|
-
def supports_block_expectations?
|
5
|
-
true
|
6
|
-
end
|
7
|
-
|
8
|
-
match do |block|
|
9
|
-
begin
|
10
|
-
block.call
|
11
|
-
rescue SystemExit => e
|
12
|
-
actual = e.status
|
13
|
-
end
|
14
|
-
actual and actual == status_code
|
15
|
-
end
|
16
|
-
|
17
|
-
chain :with_code do |status_code|
|
18
|
-
@status_code = status_code
|
19
|
-
end
|
20
|
-
|
21
|
-
failure_message do |block|
|
22
|
-
"expected block to call exit(#{status_code}) but exit" +
|
23
|
-
(actual.nil? ? " not called" : "(#{actual}) was called")
|
24
|
-
end
|
25
|
-
|
26
|
-
failure_message_when_negated do |block|
|
27
|
-
"expected block not to call exit(#{status_code})"
|
28
|
-
end
|
29
|
-
|
30
|
-
description do
|
31
|
-
"expect block to call exit(#{status_code})"
|
32
|
-
end
|
33
|
-
|
34
|
-
def status_code
|
35
|
-
@status_code ||= 0
|
36
|
-
end
|
37
|
-
end
|
1
|
+
RSpec::Matchers.define :terminate do |code|
|
2
|
+
actual = nil
|
3
|
+
|
4
|
+
def supports_block_expectations?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
match do |block|
|
9
|
+
begin
|
10
|
+
block.call
|
11
|
+
rescue SystemExit => e
|
12
|
+
actual = e.status
|
13
|
+
end
|
14
|
+
actual and actual == status_code
|
15
|
+
end
|
16
|
+
|
17
|
+
chain :with_code do |status_code|
|
18
|
+
@status_code = status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message do |block|
|
22
|
+
"expected block to call exit(#{status_code}) but exit" +
|
23
|
+
(actual.nil? ? " not called" : "(#{actual}) was called")
|
24
|
+
end
|
25
|
+
|
26
|
+
failure_message_when_negated do |block|
|
27
|
+
"expected block not to call exit(#{status_code})"
|
28
|
+
end
|
29
|
+
|
30
|
+
description do
|
31
|
+
"expect block to call exit(#{status_code})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def status_code
|
35
|
+
@status_code ||= 0
|
36
|
+
end
|
37
|
+
end
|
data/spec/wss_agent/cli_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WssAgent::CLI, vcr: true do
|
4
|
-
|
5
|
-
let(:cli) { WssAgent::CLI.new }
|
6
|
-
subject { cli }
|
7
|
-
|
8
|
-
context 'config' do
|
9
|
-
let(:output) { capture(:stdout) { subject.config } }
|
10
|
-
it "should create config file" do
|
11
|
-
expect(output).to include("Created the config file: wss_agent.yml")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'list' do
|
16
|
-
let(:output) { capture(:stdout) { subject.list } }
|
17
|
-
let(:list) {
|
18
|
-
[
|
19
|
-
{"groupId"=>"rake", "artifactId"=>"rake-10.4.2.gem", "version"=>"10.4.2", "sha1"=>"abfbf4fe8d3011f13f922adc81167af76890a627", "optional"=>false, "children"=>[], "exclusions"=>[]},
|
20
|
-
{"groupId"=>"addressable", "artifactId"=>"addressable-2.3.6.gem", "version"=>"2.3.6", "sha1"=>"dc3bdabbac99b05c3f9ec3b066ad1a41b6b55c55", "optional"=>false, "children"=>[], "exclusions"=>[]}]
|
21
|
-
}
|
22
|
-
it "returns a list dependies" do
|
23
|
-
expect(WssAgent::Specifications).to receive(:list).and_return(list)
|
24
|
-
|
25
|
-
expect(output).to eq("[\n \e[1;37m[0] \e[0m{\n \"groupId\"\e[0;37m => \e[0m\e[0;33m\"rake\"\e[0m,\n \"artifactId\"\e[0;37m => \e[0m\e[0;33m\"rake-10.4.2.gem\"\e[0m,\n \"version\"\e[0;37m => \e[0m\e[0;33m\"10.4.2\"\e[0m,\n \"sha1\"\e[0;37m => \e[0m\e[0;33m\"abfbf4fe8d3011f13f922adc81167af76890a627\"\e[0m,\n \"optional\"\e[0;37m => \e[0m\e[1;31mfalse\e[0m,\n \"children\"\e[0;37m => \e[0m[],\n \"exclusions\"\e[0;37m => \e[0m[]\n },\n \e[1;37m[1] \e[0m{\n \"groupId\"\e[0;37m => \e[0m\e[0;33m\"addressable\"\e[0m,\n \"artifactId\"\e[0;37m => \e[0m\e[0;33m\"addressable-2.3.6.gem\"\e[0m,\n \"version\"\e[0;37m => \e[0m\e[0;33m\"2.3.6\"\e[0m,\n \"sha1\"\e[0;37m => \e[0m\e[0;33m\"dc3bdabbac99b05c3f9ec3b066ad1a41b6b55c55\"\e[0m,\n \"optional\"\e[0;37m => \e[0m\e[1;31mfalse\e[0m,\n \"children\"\e[0;37m => \e[0m[],\n \"exclusions\"\e[0;37m => \e[0m[]\n }\n]\n")
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'update' do
|
31
|
-
context 'when not found token' do
|
32
|
-
let(:output) { capture(:stdout) { subject.update } }
|
33
|
-
it 'should display results' do
|
34
|
-
expect(WssAgent::Specifications).to receive(:update).and_return(double('result', success?: true))
|
35
|
-
expect{ output }.to terminate.with_code(0)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'check_policies' do
|
41
|
-
let(:output) { capture(:stdout) { subject.check_policies } }
|
42
|
-
it 'should display results' do
|
43
|
-
expect(
|
44
|
-
WssAgent::Specifications
|
45
|
-
).to receive(:check_policies).and_return(
|
46
|
-
double('result', success?: true, policy_violations?: true)
|
47
|
-
)
|
48
|
-
expect { output }.to terminate.with_code(1)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'version' do
|
53
|
-
let(:output) { capture(:stdout) { subject.version } }
|
54
|
-
it 'should display version' do
|
55
|
-
expect(output).to eq("#{WssAgent::VERSION}\n")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WssAgent::CLI, vcr: true do
|
4
|
+
|
5
|
+
let(:cli) { WssAgent::CLI.new }
|
6
|
+
subject { cli }
|
7
|
+
|
8
|
+
context 'config' do
|
9
|
+
let(:output) { capture(:stdout) { subject.config } }
|
10
|
+
it "should create config file" do
|
11
|
+
expect(output).to include("Created the config file: wss_agent.yml")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'list' do
|
16
|
+
let(:output) { capture(:stdout) { subject.list } }
|
17
|
+
let(:list) {
|
18
|
+
[
|
19
|
+
{"groupId"=>"rake", "artifactId"=>"rake-10.4.2.gem", "version"=>"10.4.2", "sha1"=>"abfbf4fe8d3011f13f922adc81167af76890a627", "optional"=>false, "children"=>[], "exclusions"=>[]},
|
20
|
+
{"groupId"=>"addressable", "artifactId"=>"addressable-2.3.6.gem", "version"=>"2.3.6", "sha1"=>"dc3bdabbac99b05c3f9ec3b066ad1a41b6b55c55", "optional"=>false, "children"=>[], "exclusions"=>[]}]
|
21
|
+
}
|
22
|
+
it "returns a list dependies" do
|
23
|
+
expect(WssAgent::Specifications).to receive(:list).and_return(list)
|
24
|
+
|
25
|
+
expect(output).to eq("[\n \e[1;37m[0] \e[0m{\n \"groupId\"\e[0;37m => \e[0m\e[0;33m\"rake\"\e[0m,\n \"artifactId\"\e[0;37m => \e[0m\e[0;33m\"rake-10.4.2.gem\"\e[0m,\n \"version\"\e[0;37m => \e[0m\e[0;33m\"10.4.2\"\e[0m,\n \"sha1\"\e[0;37m => \e[0m\e[0;33m\"abfbf4fe8d3011f13f922adc81167af76890a627\"\e[0m,\n \"optional\"\e[0;37m => \e[0m\e[1;31mfalse\e[0m,\n \"children\"\e[0;37m => \e[0m[],\n \"exclusions\"\e[0;37m => \e[0m[]\n },\n \e[1;37m[1] \e[0m{\n \"groupId\"\e[0;37m => \e[0m\e[0;33m\"addressable\"\e[0m,\n \"artifactId\"\e[0;37m => \e[0m\e[0;33m\"addressable-2.3.6.gem\"\e[0m,\n \"version\"\e[0;37m => \e[0m\e[0;33m\"2.3.6\"\e[0m,\n \"sha1\"\e[0;37m => \e[0m\e[0;33m\"dc3bdabbac99b05c3f9ec3b066ad1a41b6b55c55\"\e[0m,\n \"optional\"\e[0;37m => \e[0m\e[1;31mfalse\e[0m,\n \"children\"\e[0;37m => \e[0m[],\n \"exclusions\"\e[0;37m => \e[0m[]\n }\n]\n")
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'update' do
|
31
|
+
context 'when not found token' do
|
32
|
+
let(:output) { capture(:stdout) { subject.update } }
|
33
|
+
it 'should display results' do
|
34
|
+
expect(WssAgent::Specifications).to receive(:update).and_return(double('result', success?: true))
|
35
|
+
expect{ output }.to terminate.with_code(0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'check_policies' do
|
41
|
+
let(:output) { capture(:stdout) { subject.check_policies } }
|
42
|
+
it 'should display results' do
|
43
|
+
expect(
|
44
|
+
WssAgent::Specifications
|
45
|
+
).to receive(:check_policies).and_return(
|
46
|
+
double('result', success?: true, policy_violations?: true)
|
47
|
+
)
|
48
|
+
expect { output }.to terminate.with_code(1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'version' do
|
53
|
+
let(:output) { capture(:stdout) { subject.version } }
|
54
|
+
it 'should display version' do
|
55
|
+
expect(output).to eq("#{WssAgent::VERSION}\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,151 +1,151 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WssAgent::Client, vcr: true do
|
4
|
-
let(:user_key){ '9ec685d4f32843c2b963e3556256489e273cb1a122f948ba93463ffba6f1ed8c' }
|
5
|
-
let(:bad_request_response) {
|
6
|
-
{"envelopeVersion"=>"2.1.0", "status"=>2, "message"=>"Illegal arguments", "data"=>"Unsupported agent: null"}
|
7
|
-
}
|
8
|
-
let(:success_response) {
|
9
|
-
"{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"Tom Test\\\",\\\"updatedProjects\\\":[],\\\"createdProjects\\\":[]}\"}"
|
10
|
-
}
|
11
|
-
let(:server_error_response) {
|
12
|
-
"<html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size=\"1\" noshade=\"noshade\"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.NullPointerException\n\tcom.wss.service.agent.impl.AgentRequestParams.extractUpdateParams(AgentRequestParams.java:155)\n\tcom.wss.service.agent.impl.AgentRequestParams.fromHttpRequest(AgentRequestParams.java:133)\n\tcom.wss.service.agent.AgentServlet.doPost(AgentServlet.java:71)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:754)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:847)\n</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.</u></p><HR size=\"1\" noshade=\"noshade\"><h3>JBoss Web/7.0.13.Final</h3></body></html>"
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:wss_client) { WssAgent::Client.new }
|
16
|
-
|
17
|
-
before do
|
18
|
-
allow(WssAgent::Configure).to receive_messages(token: 'xxxxxx')
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
describe '#payload' do
|
23
|
-
let(:payload) {
|
24
|
-
{
|
25
|
-
agent: "bundler-plugin",
|
26
|
-
agentVersion: "1.0",
|
27
|
-
token: "xxxxxx",
|
28
|
-
product: "",
|
29
|
-
productVersion: "",
|
30
|
-
diff: "[{\"coordinates\":{\"artifactId\":\"wss_agent\",\"version\":\"#{WssAgent::VERSION}\"},\"dependencies\":{}}]",
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
}
|
35
|
-
it 'should return request params with userKey' do
|
36
|
-
allow(WssAgent::Configure).to receive_messages(user_key: user_key)
|
37
|
-
Timecop.freeze(Time.now) do
|
38
|
-
payload_params = payload.merge(
|
39
|
-
timeStamp: Time.now.to_i,
|
40
|
-
userKey: user_key
|
41
|
-
)
|
42
|
-
|
43
|
-
expect(wss_client.payload({})).to eq(payload_params)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
it 'should return request params without userKey' do
|
47
|
-
Timecop.freeze(Time.now) do
|
48
|
-
payload_params = payload.merge(timeStamp: Time.now.to_i)
|
49
|
-
expect(wss_client.payload({})).to eq(payload_params)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#diff' do
|
55
|
-
let(:diff) {
|
56
|
-
"[{\"coordinates\":{\"artifactId\":\"wss_agent\",\"version\":\"#{WssAgent::VERSION}\"},\"dependencies\":[{\"groupId\":\"bacon\",\"artifactId\":\"bacon-1.2.0.gem\",\"version\":\"1.2.0\",\"sha1\":\"xxxxxxxxxxxxxxxxxxxxxxx\",\"optional\":\"\",\"children\":\"\",\"exclusions\":\"\"}]}]"
|
57
|
-
}
|
58
|
-
let(:gem_list) {
|
59
|
-
[
|
60
|
-
{
|
61
|
-
'groupId' => 'bacon',
|
62
|
-
'artifactId' => 'bacon-1.2.0.gem',
|
63
|
-
'version' => '1.2.0',
|
64
|
-
'sha1' => 'xxxxxxxxxxxxxxxxxxxxxxx',
|
65
|
-
'optional' => '',
|
66
|
-
'children' => '',
|
67
|
-
'exclusions' => ''
|
68
|
-
}
|
69
|
-
]
|
70
|
-
}
|
71
|
-
it 'should diff of gem list' do
|
72
|
-
expect(wss_client.diff(gem_list)).to eq(diff)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
describe '#update' do
|
78
|
-
|
79
|
-
context 'success' do
|
80
|
-
before do
|
81
|
-
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
82
|
-
to_return(status: 200,
|
83
|
-
body: success_response,
|
84
|
-
headers: {})
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
subject { wss_client.update(WssAgent::Specifications.list) }
|
89
|
-
|
90
|
-
it 'response should be success' do
|
91
|
-
expect(subject).to be_success
|
92
|
-
end
|
93
|
-
it 'should return message response' do
|
94
|
-
expect(subject.message).to eq("White Source update results: \n White Source organization: Tom Test \n No new projects found \n\n No projects were updated \n")
|
95
|
-
end
|
96
|
-
it 'should return status of response' do
|
97
|
-
expect(subject.status).to eq(1)
|
98
|
-
end
|
99
|
-
it 'should response json data' do
|
100
|
-
expect(subject.data).to eq({"organization"=>"Tom Test", "updatedProjects"=>[], "createdProjects"=>[]})
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'bad request' do
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'server error' do
|
109
|
-
before do
|
110
|
-
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
111
|
-
to_return(status: 200,
|
112
|
-
body: server_error_response,
|
113
|
-
headers: {})
|
114
|
-
|
115
|
-
end
|
116
|
-
subject { wss_client.update(WssAgent::Specifications.list) }
|
117
|
-
it 'response should be success' do
|
118
|
-
expect(subject).to_not be_success
|
119
|
-
end
|
120
|
-
it 'should return message response' do
|
121
|
-
expect(subject.message).to eq(server_error_response)
|
122
|
-
end
|
123
|
-
it 'should return status of response' do
|
124
|
-
expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
|
125
|
-
end
|
126
|
-
it 'should response json data' do
|
127
|
-
expect(subject.data).to be_nil
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'server timeout' do
|
132
|
-
before do
|
133
|
-
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
134
|
-
to_timeout
|
135
|
-
end
|
136
|
-
subject { wss_client.update(WssAgent::Specifications.list) }
|
137
|
-
it 'response should be success' do
|
138
|
-
expect(subject).to_not be_success
|
139
|
-
end
|
140
|
-
it 'should return message response' do
|
141
|
-
expect(subject.message).to eq("Excon::Error::Timeout")
|
142
|
-
end
|
143
|
-
it 'should return status of response' do
|
144
|
-
expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
|
145
|
-
end
|
146
|
-
it 'should response json data' do
|
147
|
-
expect(subject.data).to be_nil
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WssAgent::Client, vcr: true do
|
4
|
+
let(:user_key){ '9ec685d4f32843c2b963e3556256489e273cb1a122f948ba93463ffba6f1ed8c' }
|
5
|
+
let(:bad_request_response) {
|
6
|
+
{"envelopeVersion"=>"2.1.0", "status"=>2, "message"=>"Illegal arguments", "data"=>"Unsupported agent: null"}
|
7
|
+
}
|
8
|
+
let(:success_response) {
|
9
|
+
"{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"Tom Test\\\",\\\"updatedProjects\\\":[],\\\"createdProjects\\\":[]}\"}"
|
10
|
+
}
|
11
|
+
let(:server_error_response) {
|
12
|
+
"<html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size=\"1\" noshade=\"noshade\"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.NullPointerException\n\tcom.wss.service.agent.impl.AgentRequestParams.extractUpdateParams(AgentRequestParams.java:155)\n\tcom.wss.service.agent.impl.AgentRequestParams.fromHttpRequest(AgentRequestParams.java:133)\n\tcom.wss.service.agent.AgentServlet.doPost(AgentServlet.java:71)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:754)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:847)\n</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.</u></p><HR size=\"1\" noshade=\"noshade\"><h3>JBoss Web/7.0.13.Final</h3></body></html>"
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:wss_client) { WssAgent::Client.new }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(WssAgent::Configure).to receive_messages(token: 'xxxxxx')
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe '#payload' do
|
23
|
+
let(:payload) {
|
24
|
+
{
|
25
|
+
agent: "bundler-plugin",
|
26
|
+
agentVersion: "1.0",
|
27
|
+
token: "xxxxxx",
|
28
|
+
product: "",
|
29
|
+
productVersion: "",
|
30
|
+
diff: "[{\"coordinates\":{\"artifactId\":\"wss_agent\",\"version\":\"#{WssAgent::VERSION}\"},\"dependencies\":{}}]",
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
}
|
35
|
+
it 'should return request params with userKey' do
|
36
|
+
allow(WssAgent::Configure).to receive_messages(user_key: user_key)
|
37
|
+
Timecop.freeze(Time.now) do
|
38
|
+
payload_params = payload.merge(
|
39
|
+
timeStamp: Time.now.to_i,
|
40
|
+
userKey: user_key
|
41
|
+
)
|
42
|
+
|
43
|
+
expect(wss_client.payload({})).to eq(payload_params)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
it 'should return request params without userKey' do
|
47
|
+
Timecop.freeze(Time.now) do
|
48
|
+
payload_params = payload.merge(timeStamp: Time.now.to_i)
|
49
|
+
expect(wss_client.payload({})).to eq(payload_params)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#diff' do
|
55
|
+
let(:diff) {
|
56
|
+
"[{\"coordinates\":{\"artifactId\":\"wss_agent\",\"version\":\"#{WssAgent::VERSION}\"},\"dependencies\":[{\"groupId\":\"bacon\",\"artifactId\":\"bacon-1.2.0.gem\",\"version\":\"1.2.0\",\"sha1\":\"xxxxxxxxxxxxxxxxxxxxxxx\",\"optional\":\"\",\"children\":\"\",\"exclusions\":\"\"}]}]"
|
57
|
+
}
|
58
|
+
let(:gem_list) {
|
59
|
+
[
|
60
|
+
{
|
61
|
+
'groupId' => 'bacon',
|
62
|
+
'artifactId' => 'bacon-1.2.0.gem',
|
63
|
+
'version' => '1.2.0',
|
64
|
+
'sha1' => 'xxxxxxxxxxxxxxxxxxxxxxx',
|
65
|
+
'optional' => '',
|
66
|
+
'children' => '',
|
67
|
+
'exclusions' => ''
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
it 'should diff of gem list' do
|
72
|
+
expect(wss_client.diff(gem_list)).to eq(diff)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
describe '#update' do
|
78
|
+
|
79
|
+
context 'success' do
|
80
|
+
before do
|
81
|
+
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
82
|
+
to_return(status: 200,
|
83
|
+
body: success_response,
|
84
|
+
headers: {})
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
subject { wss_client.update(WssAgent::Specifications.list) }
|
89
|
+
|
90
|
+
it 'response should be success' do
|
91
|
+
expect(subject).to be_success
|
92
|
+
end
|
93
|
+
it 'should return message response' do
|
94
|
+
expect(subject.message).to eq("White Source update results: \n White Source organization: Tom Test \n No new projects found \n\n No projects were updated \n")
|
95
|
+
end
|
96
|
+
it 'should return status of response' do
|
97
|
+
expect(subject.status).to eq(1)
|
98
|
+
end
|
99
|
+
it 'should response json data' do
|
100
|
+
expect(subject.data).to eq({"organization"=>"Tom Test", "updatedProjects"=>[], "createdProjects"=>[]})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'bad request' do
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'server error' do
|
109
|
+
before do
|
110
|
+
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
111
|
+
to_return(status: 200,
|
112
|
+
body: server_error_response,
|
113
|
+
headers: {})
|
114
|
+
|
115
|
+
end
|
116
|
+
subject { wss_client.update(WssAgent::Specifications.list) }
|
117
|
+
it 'response should be success' do
|
118
|
+
expect(subject).to_not be_success
|
119
|
+
end
|
120
|
+
it 'should return message response' do
|
121
|
+
expect(subject.message).to eq(server_error_response)
|
122
|
+
end
|
123
|
+
it 'should return status of response' do
|
124
|
+
expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
|
125
|
+
end
|
126
|
+
it 'should response json data' do
|
127
|
+
expect(subject.data).to be_nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'server timeout' do
|
132
|
+
before do
|
133
|
+
stub_request(:post, "https://saas.whitesourcesoftware.com/agent").
|
134
|
+
to_timeout
|
135
|
+
end
|
136
|
+
subject { wss_client.update(WssAgent::Specifications.list) }
|
137
|
+
it 'response should be success' do
|
138
|
+
expect(subject).to_not be_success
|
139
|
+
end
|
140
|
+
it 'should return message response' do
|
141
|
+
expect(subject.message).to eq("Excon::Error::Timeout")
|
142
|
+
end
|
143
|
+
it 'should return status of response' do
|
144
|
+
expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
|
145
|
+
end
|
146
|
+
it 'should response json data' do
|
147
|
+
expect(subject.data).to be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|