wss_agent 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +201 -0
  7. data/README.md +73 -0
  8. data/Rakefile +10 -0
  9. data/bin/wss_agent +13 -0
  10. data/lib/config/custom_default.yml +5 -0
  11. data/lib/config/default.yml +11 -0
  12. data/lib/wss_agent/cli.rb +49 -0
  13. data/lib/wss_agent/client.rb +59 -0
  14. data/lib/wss_agent/configure.rb +90 -0
  15. data/lib/wss_agent/gem_sha1.rb +76 -0
  16. data/lib/wss_agent/project.rb +45 -0
  17. data/lib/wss_agent/response.rb +57 -0
  18. data/lib/wss_agent/response_inventory.rb +28 -0
  19. data/lib/wss_agent/response_policies.rb +76 -0
  20. data/lib/wss_agent/specifications.rb +150 -0
  21. data/lib/wss_agent/version.rb +4 -0
  22. data/lib/wss_agent.rb +40 -0
  23. data/spec/fixtures/vcr_cassettes/WssAgent_CLI/update/when_not_found_token/should_display_error_message.yml +2984 -0
  24. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/response_should_be_success.yml +2984 -0
  25. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_response_json_data.yml +2984 -0
  26. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_message_response.yml +2984 -0
  27. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_status_of_response.yml +2984 -0
  28. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/response_should_be_success.yml +2984 -0
  29. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_response_json_data.yml +2984 -0
  30. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_message_response.yml +2984 -0
  31. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_status_of_response.yml +2984 -0
  32. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/response_should_be_success.yml +2984 -0
  33. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_response_json_data.yml +2984 -0
  34. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_message_response.yml +2984 -0
  35. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_status_of_response.yml +2984 -0
  36. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_check_policies/should_check_policies.yml +50 -0
  37. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/should_update_list_gems_on_server.yml +50 -0
  38. 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 -0
  39. 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 -0
  40. data/spec/fixtures/wss_agent.yml +9 -0
  41. data/spec/spec_helper.rb +35 -0
  42. data/spec/wss_agent/cli_spec.rb +57 -0
  43. data/spec/wss_agent/client_spec.rb +137 -0
  44. data/spec/wss_agent/configure_spec.rb +148 -0
  45. data/spec/wss_agent/specifications_spec.rb +137 -0
  46. data/wss_agent.gemspec +38 -0
  47. metadata +390 -0
@@ -0,0 +1,9 @@
1
+ ---
2
+ url: http://saas.whitesourcesoftware.com
3
+ token: 11111111-1111-1111-1111-111111111112
4
+ check_policies: false
5
+ agent: bundler-plugin
6
+ agent_version: '1.0'
7
+ product: 'Test product'
8
+ product_version: '1.0.1'
9
+
@@ -0,0 +1,35 @@
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
+
10
+ VCR.configure do |config|
11
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
12
+ config.hook_into :webmock
13
+ config.configure_rspec_metadata!
14
+ config.allow_http_connections_when_no_cassette = false
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+
23
+ def capture(stream)
24
+ begin
25
+ stream = stream.to_s
26
+ eval "$#{stream} = StringIO.new"
27
+ yield
28
+ result = eval("$#{stream}").string
29
+ ensure
30
+ eval("$#{stream} = #{stream.upcase}")
31
+ end
32
+ result
33
+ end
34
+
35
+ end
@@ -0,0 +1,57 @@
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
+ let(:output) { capture(:stdout) { subject.update } }
32
+ context 'when not found token' do
33
+ it 'should display error message' do
34
+ expect(output).to eq("\e[0;33m\"Can't find Token, please add your Whitesource API token in the wss_agent.yml file\"\e[0m\n")
35
+ end
36
+ end
37
+ it 'should display results' do
38
+ expect(WssAgent::Specifications).to receive(:update).and_return([])
39
+ expect(output).to eq("")
40
+ end
41
+ end
42
+
43
+ context 'check_policies' do
44
+ let(:output) { capture(:stdout) { subject.check_policies } }
45
+ it 'should display results' do
46
+ expect(WssAgent::Specifications).to receive(:check_policies).and_return([])
47
+ expect(output).to eq("")
48
+ end
49
+ end
50
+
51
+ context 'version' do
52
+ let(:output) { capture(:stdout) { subject.version } }
53
+ it 'should display version' do
54
+ expect(output).to eq("#{WssAgent::VERSION}\n")
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe WssAgent::Client, vcr: true do
4
+ let(:bad_request_response) {
5
+ {"envelopeVersion"=>"2.1.0", "status"=>2, "message"=>"Illegal arguments", "data"=>"Unsupported agent: null"}
6
+ }
7
+ let(:success_response) {
8
+ "{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"Tom Test\\\",\\\"updatedProjects\\\":[],\\\"createdProjects\\\":[]}\"}"
9
+ }
10
+ let(:server_error_response) {
11
+ "<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>"
12
+ }
13
+
14
+ let(:wss_client) { WssAgent::Client.new }
15
+
16
+ before do
17
+ allow(WssAgent::Configure).to receive_messages(token: 'xxxxxx')
18
+ end
19
+
20
+
21
+ describe '#payload' do
22
+
23
+ it 'should return request params' do
24
+ Timecop.freeze(Time.now) do
25
+ payload = {
26
+ agent: "bundler-plugin",
27
+ agentVersion: "1.0",
28
+ token: "xxxxxx",
29
+ product: "",
30
+ productVersion: "",
31
+ timeStamp: Time.now.to_i,
32
+ diff: "[{\"coordinates\":{\"artifactId\":\"wss_agent\",\"version\":\"#{WssAgent::VERSION}\"},\"dependencies\":{}}]"
33
+ }
34
+
35
+ expect(wss_client.payload({})).to eq(payload)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#diff' do
41
+ let(:diff) {
42
+ "[{\"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\":\"\"}]}]"
43
+ }
44
+ let(:gem_list) {
45
+ [
46
+ {
47
+ 'groupId' => 'bacon',
48
+ 'artifactId' => 'bacon-1.2.0.gem',
49
+ 'version' => '1.2.0',
50
+ 'sha1' => 'xxxxxxxxxxxxxxxxxxxxxxx',
51
+ 'optional' => '',
52
+ 'children' => '',
53
+ 'exclusions' => ''
54
+ }
55
+ ]
56
+ }
57
+ it 'should diff of gem list' do
58
+ expect(wss_client.diff(gem_list)).to eq(diff)
59
+ end
60
+ end
61
+
62
+
63
+ describe '#update' do
64
+
65
+ context 'success' do
66
+ before do
67
+ stub_request(:post, "http://saas.whitesourcesoftware.com/agent").
68
+ to_return(status: 200,
69
+ body: success_response,
70
+ headers: {})
71
+
72
+ end
73
+
74
+ subject { wss_client.update(WssAgent::Specifications.list) }
75
+
76
+ it 'response should be success' do
77
+ expect(subject).to be_success
78
+ end
79
+ it 'should return message response' do
80
+ 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")
81
+ end
82
+ it 'should return status of response' do
83
+ expect(subject.status).to eq(1)
84
+ end
85
+ it 'should response json data' do
86
+ expect(subject.data).to eq({"organization"=>"Tom Test", "updatedProjects"=>[], "createdProjects"=>[]})
87
+ end
88
+ end
89
+
90
+ context 'bad request' do
91
+
92
+ end
93
+
94
+ context 'server error' do
95
+ before do
96
+ stub_request(:post, "http://saas.whitesourcesoftware.com/agent").
97
+ to_return(status: 200,
98
+ body: server_error_response,
99
+ headers: {})
100
+
101
+ end
102
+ subject { wss_client.update(WssAgent::Specifications.list) }
103
+ it 'response should be success' do
104
+ expect(subject).to_not be_success
105
+ end
106
+ it 'should return message response' do
107
+ expect(subject.message).to eq(server_error_response)
108
+ end
109
+ it 'should return status of response' do
110
+ expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
111
+ end
112
+ it 'should response json data' do
113
+ expect(subject.data).to be_nil
114
+ end
115
+ end
116
+
117
+ context 'server timeout' do
118
+ before do
119
+ stub_request(:post, "http://saas.whitesourcesoftware.com/agent").
120
+ to_timeout
121
+ end
122
+ subject { wss_client.update(WssAgent::Specifications.list) }
123
+ it 'response should be success' do
124
+ expect(subject).to_not be_success
125
+ end
126
+ it 'should return message response' do
127
+ expect(subject.message).to eq("Excon::Errors::Timeout")
128
+ end
129
+ it 'should return status of response' do
130
+ expect(subject.status).to eq(WssAgent::Response::SERVER_ERROR_STATUS)
131
+ end
132
+ it 'should response json data' do
133
+ expect(subject.data).to be_nil
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe WssAgent::Configure do
4
+ let(:default_config) {
5
+ {
6
+ 'url' => 'http://saas.whitesourcesoftware.com/agent',
7
+ 'token'=>'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
8
+ "check_policies"=>false,
9
+ 'agent' => 'bundler-plugin',
10
+ 'agent_version' => '1.0',
11
+ 'product' => '',
12
+ 'product_version' => '',
13
+ 'coordinates' => {"artifact_id"=>"", "version"=>""}
14
+ }
15
+ }
16
+
17
+ describe '.default_path' do
18
+ it 'should return path of default config' do
19
+ expect(WssAgent::Configure.default_path).to match(/\/lib\/config\/default\.yml\Z/)
20
+ end
21
+ end
22
+
23
+ describe '.exist_default_config?' do
24
+ it 'should be true' do
25
+ expect(WssAgent::Configure.exist_default_config?).to be true
26
+ end
27
+ end
28
+
29
+ describe '.default' do
30
+ it 'should default config' do
31
+ expect(WssAgent::Configure.default).to eq(default_config)
32
+ end
33
+ end
34
+
35
+ describe '.current_path' do
36
+ it 'should return locally config path' do
37
+ expect(WssAgent::Configure.current_path).to match(/wss_agent\.yml\Z/)
38
+ end
39
+ end
40
+
41
+ describe '.check_policies' do
42
+ context 'default' do
43
+ it 'should be "false"' do
44
+ expect(WssAgent::Configure['check_policies']).to be false
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '.current' do
50
+ context 'when locally config is not found' do
51
+ it 'should return default config' do
52
+ allow(WssAgent::Configure).to receive(:current_path).and_return('miss.yml')
53
+ expect(WssAgent::Configure.current).to eq(default_config)
54
+ end
55
+ end
56
+ context 'when locally config is found' do
57
+ before do
58
+ allow(WssAgent::Configure).to receive(:current_path)
59
+ .and_return(File.join(File.expand_path('../..', __FILE__), 'fixtures/wss_agent.yml'))
60
+ end
61
+ it 'should return locally config' do
62
+ expect(WssAgent::Configure.current).to eq({
63
+ "url" => "http://saas.whitesourcesoftware.com",
64
+ "token" => "11111111-1111-1111-1111-111111111112",
65
+ "check_policies" => false,
66
+ "agent" => "bundler-plugin",
67
+ "agent_version" => "1.0",
68
+ "coordinates" => {"artifact_id"=>"", "version"=>""},
69
+ "product" => "Test product",
70
+ "product_version" => "1.0.1"
71
+ })
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '.url' do
77
+ context 'when url is empty' do
78
+ before do
79
+ allow(WssAgent::Configure).to receive_messages(current: {})
80
+ end
81
+ it 'should cause an exception' do
82
+ expect{ WssAgent::Configure.url }.to raise_error(WssAgent::ApiUrlNotFound)
83
+ end
84
+ end
85
+ context 'when url is exist' do
86
+ it 'should return url' do
87
+ expect(WssAgent::Configure.url).to eq('http://saas.whitesourcesoftware.com')
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '.token' do
93
+ context 'when token is not found' do
94
+ it 'should cause an exception' do
95
+ expect{ WssAgent::Configure.token }.to raise_error(WssAgent::TokenNotFound)
96
+ end
97
+ end
98
+ context 'when token is found' do
99
+ let(:config) {
100
+ {
101
+ 'url' => 'http://saas.whitesourcesoftware.com',
102
+ 'token' => '11111111-1111-1111-1111-111111111111'
103
+ }
104
+ }
105
+ before do
106
+ allow(WssAgent::Configure).to receive_messages(current: config)
107
+ end
108
+
109
+ it 'should return token' do
110
+ expect(WssAgent::Configure.token).to eq('11111111-1111-1111-1111-111111111111')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe '.agent' do
116
+ it 'should be "bundler-plugin"' do
117
+ expect(WssAgent::Configure['agent']).to eq('bundler-plugin')
118
+ end
119
+ end
120
+
121
+ describe '.agent_version' do
122
+ it 'should be "1.0"' do
123
+ expect(WssAgent::Configure['agent_version']).to eq('1.0')
124
+ end
125
+ end
126
+
127
+ describe '.product' do
128
+ before do
129
+ allow(WssAgent::Configure).to receive(:current_path)
130
+ .and_return(File.join(File.expand_path('../..', __FILE__), 'fixtures/wss_agent.yml'))
131
+ end
132
+
133
+ it 'should be "Test product"' do
134
+ expect(WssAgent::Configure['product']).to eq('Test product')
135
+ end
136
+ end
137
+
138
+ describe '.product_version' do
139
+ before do
140
+ allow(WssAgent::Configure).to receive(:current_path)
141
+ .and_return(File.join(File.expand_path('../..', __FILE__), 'fixtures/wss_agent.yml'))
142
+ end
143
+
144
+ it 'should be "1.0.1"' do
145
+ expect(WssAgent::Configure['product_version']).to eq('1.0.1')
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe WssAgent::Specifications, vcr: true do
4
+ before do
5
+ allow(WssAgent::Configure).to receive_messages(token: 'xxxxxx')
6
+ end
7
+
8
+ let(:gem_list) {
9
+ [
10
+ {
11
+ 'groupId' => 'bacon',
12
+ 'artifactId' => 'bacon-1.2.0.gem',
13
+ 'version' => '1.2.0',
14
+ 'sha1' => 'xxxxxxxxxxxxxxxxxxxxxxx',
15
+ 'optional' => '',
16
+ 'children' => '',
17
+ 'exclusions' => ''
18
+ }
19
+ ]
20
+ }
21
+
22
+ describe '.check_policies' do
23
+ let(:success_response) {
24
+ WssAgent::ResponsePolicies.new(
25
+ Faraday::Response.new(
26
+ body:
27
+ "{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"TestParallel588\\\",\\\"existingProjects\\\":{\\\"TestProjectUbuntu\\\":{\\\"children\\\":[]}},\\\"newProjects\\\":{},\\\"projectNewResources\\\":{\\\"TestProjectUbuntu\\\":[]}}\"}",
28
+ status: 200))
29
+ }
30
+
31
+ it 'should check policies' do
32
+ Timecop.freeze(Time.now) do
33
+ allow_any_instance_of(WssAgent::Client).to receive(:check_policies)
34
+ .and_return(success_response)
35
+
36
+ allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
37
+ expect(capture(:stdout) {WssAgent::Specifications.check_policies}).to eq("All dependencies conform with open source policies\n")
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.update' do
43
+ let(:wss_client) { WssAgent::Client.new }
44
+ let(:success_response) {
45
+ WssAgent::ResponseInventory.new(
46
+ Faraday::Response.new(
47
+ body:
48
+ "{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"Tom Test\\\",\\\"updatedProjects\\\":[],\\\"createdProjects\\\":[]}\"}",
49
+ status: 200))
50
+ }
51
+ let(:policy_success_response) {
52
+ WssAgent::ResponsePolicies.new(
53
+ Faraday::Response.new(
54
+ body:
55
+ "{\"envelopeVersion\":\"2.1.0\",\"status\":1,\"message\":\"ok\",\"data\":\"{\\\"organization\\\":\\\"TestParallel588\\\",\\\"existingProjects\\\":{\\\"TestProjectUbuntu\\\":{\\\"children\\\":[]}},\\\"newProjects\\\":{},\\\"projectNewResources\\\":{\\\"TestProjectUbuntu\\\":[]}}\"}",
56
+ status: 200))
57
+ }
58
+
59
+ it 'should update list gems on server' do
60
+ Timecop.freeze(Time.now) do
61
+ allow_any_instance_of(WssAgent::Client).to receive(:update)
62
+ .and_return(success_response)
63
+ allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
64
+ expect(WssAgent::Specifications.update).to be true
65
+ end
66
+ end
67
+
68
+ context 'when check_policies is true' do
69
+
70
+ before {
71
+ allow(WssAgent::Client).to receive(:new).and_return(wss_client)
72
+ allow(WssAgent::Configure).to receive(:current)
73
+ .and_return(WssAgent::Configure.default.merge({'check_policies' => true}))
74
+ }
75
+ context 'and check policies return a violation' do
76
+ it 'should not update inventory' do
77
+ allow(policy_success_response).to receive(:policy_violations?).and_return(true)
78
+ expect(wss_client).to receive(:check_policies).and_return(policy_success_response)
79
+ expect(wss_client).to_not receive(:update)
80
+
81
+ expect(WssAgent::Specifications.update).to be false
82
+ end
83
+ end
84
+
85
+ context 'and check policies returns without a violation' do
86
+ it 'should update inventory' do
87
+ allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
88
+ allow(policy_success_response).to receive(:policy_violations?).and_return(false)
89
+ expect(wss_client).to receive(:check_policies).and_return(policy_success_response)
90
+ expect(wss_client).to receive(:update).and_return(success_response)
91
+
92
+ expect(WssAgent::Specifications.update).to be true
93
+ end
94
+ end
95
+ end
96
+
97
+ context 'when check_policies is false' do
98
+ before {
99
+ allow(WssAgent::Client).to receive(:new).and_return(wss_client)
100
+ allow(WssAgent::Configure).to receive(:current)
101
+ .and_return(WssAgent::Configure.default.merge({'check_policies' => false}))
102
+ }
103
+ it 'should update inventory' do
104
+ allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
105
+
106
+ expect(wss_client).to_not receive(:check_policies)
107
+ expect(wss_client).to receive(:update).and_return(success_response)
108
+
109
+ expect(WssAgent::Specifications.update).to be true
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '.list' do
115
+ it 'should build list gems'do
116
+ allow_any_instance_of(WssAgent::GemSha1).to receive(:sha1).and_return("85b19b68a33f1dc0e147ff08bad66f7cfc52de36")
117
+
118
+ load_specs = double(specs: Bundler::SpecSet.new([Gem::Specification.new('bacon', '1.2.0')]))
119
+ allow(Bundler).to receive(:load).and_return(load_specs)
120
+ expect(WssAgent::Specifications.list).to eq([{"groupId"=>"bacon",
121
+ "artifactId"=>"bacon-1.2.0.gem",
122
+ "version"=>"1.2.0",
123
+ "sha1"=>"85b19b68a33f1dc0e147ff08bad66f7cfc52de36",
124
+ "optional"=>false,
125
+ "children"=>[], "exclusions"=>[]}])
126
+ end
127
+ end
128
+
129
+ describe '.specs' do
130
+ it 'load bundle spec' do
131
+ specs_double = double
132
+ expect(specs_double).to receive(:specs).and_return([])
133
+ expect(Bundler).to receive(:load).and_return(specs_double)
134
+ WssAgent::Specifications.specs
135
+ end
136
+ end
137
+ end
data/wss_agent.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wss_agent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wss_agent"
8
+ spec.version = WssAgent::VERSION
9
+ spec.authors = ["Maxim Pechnikov"]
10
+ spec.email = ["parallel588@gmail.com"]
11
+ spec.summary = %q{White Source agent.}
12
+ spec.description = %q{White Source agent to sync gems}
13
+ spec.homepage = "https://github.com/whitesource/ruby-plugin"
14
+ spec.license = "Apache License 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.executables = %w(wss_agent)
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "pry", '~> 0.10', '>= 0.10.1'
25
+ spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
26
+ spec.add_development_dependency 'webmock', '~> 1.20', '>= 1.20.4'
27
+ spec.add_development_dependency 'timecop', '~> 0.7', '>= 0.7.1'
28
+ spec.add_development_dependency "yard", "~> 0.8"
29
+ spec.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.3'
30
+
31
+ spec.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
32
+ spec.add_dependency 'yell', '~> 2.0', '>= 2.0.5'
33
+ spec.add_dependency 'excon', '~> 0.42.1'
34
+ spec.add_dependency 'faraday', '~> 0.9', '>= 0.9.1'
35
+ spec.add_dependency 'faraday_middleware', '~> 0.9', '>= 0.9.1'
36
+ spec.add_dependency 'awesome_print', '~> 1.6', '>= 1.6.0'
37
+ spec.add_dependency 'oj', '~> 2.11', '>= 2.11.2'
38
+ end