artifactory 2.8.2 → 3.0.0

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.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/lib/artifactory.rb +1 -1
  3. data/lib/artifactory/client.rb +1 -1
  4. data/lib/artifactory/collections/artifact.rb +1 -1
  5. data/lib/artifactory/collections/base.rb +1 -1
  6. data/lib/artifactory/collections/build.rb +1 -1
  7. data/lib/artifactory/configurable.rb +1 -1
  8. data/lib/artifactory/defaults.rb +1 -1
  9. data/lib/artifactory/errors.rb +5 -5
  10. data/lib/artifactory/resources/artifact.rb +12 -12
  11. data/lib/artifactory/resources/backup.rb +1 -1
  12. data/lib/artifactory/resources/base.rb +2 -2
  13. data/lib/artifactory/resources/build.rb +2 -2
  14. data/lib/artifactory/resources/group.rb +1 -1
  15. data/lib/artifactory/resources/layout.rb +1 -1
  16. data/lib/artifactory/resources/ldap_setting.rb +1 -1
  17. data/lib/artifactory/resources/mail_server.rb +1 -1
  18. data/lib/artifactory/resources/permission_target.rb +15 -1
  19. data/lib/artifactory/resources/plugin.rb +1 -1
  20. data/lib/artifactory/resources/repository.rb +1 -1
  21. data/lib/artifactory/resources/system.rb +1 -1
  22. data/lib/artifactory/resources/url_base.rb +1 -1
  23. data/lib/artifactory/resources/user.rb +1 -1
  24. data/lib/artifactory/util.rb +2 -2
  25. data/lib/artifactory/version.rb +2 -2
  26. metadata +10 -130
  27. data/.gitignore +0 -27
  28. data/.travis.yml +0 -28
  29. data/CHANGELOG.md +0 -141
  30. data/Gemfile +0 -14
  31. data/README.md +0 -288
  32. data/Rakefile +0 -28
  33. data/appveyor.yml +0 -30
  34. data/artifactory.gemspec +0 -25
  35. data/spec/integration/resources/artifact_spec.rb +0 -99
  36. data/spec/integration/resources/backup.rb +0 -22
  37. data/spec/integration/resources/build_component_spec.rb +0 -64
  38. data/spec/integration/resources/build_spec.rb +0 -38
  39. data/spec/integration/resources/group_spec.rb +0 -45
  40. data/spec/integration/resources/layout_spec.rb +0 -22
  41. data/spec/integration/resources/ldap_setting_spec.rb +0 -22
  42. data/spec/integration/resources/mail_server_spec.rb +0 -22
  43. data/spec/integration/resources/permission_target_spec.rb +0 -75
  44. data/spec/integration/resources/repository_spec.rb +0 -40
  45. data/spec/integration/resources/system_spec.rb +0 -58
  46. data/spec/integration/resources/url_base_spec.rb +0 -22
  47. data/spec/integration/resources/user_spec.rb +0 -45
  48. data/spec/spec_helper.rb +0 -52
  49. data/spec/support/api_server.rb +0 -49
  50. data/spec/support/api_server/artifact_endpoints.rb +0 -186
  51. data/spec/support/api_server/build_component_endpoints.rb +0 -44
  52. data/spec/support/api_server/build_endpoints.rb +0 -240
  53. data/spec/support/api_server/group_endpoints.rb +0 -53
  54. data/spec/support/api_server/permission_target_endpoints.rb +0 -53
  55. data/spec/support/api_server/repository_endpoints.rb +0 -114
  56. data/spec/support/api_server/status_endpoints.rb +0 -11
  57. data/spec/support/api_server/system_endpoints.rb +0 -104
  58. data/spec/support/api_server/user_endpoints.rb +0 -59
  59. data/spec/unit/artifactory_spec.rb +0 -73
  60. data/spec/unit/client_spec.rb +0 -132
  61. data/spec/unit/resources/artifact_spec.rb +0 -608
  62. data/spec/unit/resources/backup_spec.rb +0 -61
  63. data/spec/unit/resources/base_spec.rb +0 -180
  64. data/spec/unit/resources/build_component_spec.rb +0 -118
  65. data/spec/unit/resources/build_spec.rb +0 -347
  66. data/spec/unit/resources/defaults_spec.rb +0 -27
  67. data/spec/unit/resources/group_spec.rb +0 -108
  68. data/spec/unit/resources/layout_spec.rb +0 -61
  69. data/spec/unit/resources/ldap_setting_spec.rb +0 -65
  70. data/spec/unit/resources/mail_server_spec.rb +0 -57
  71. data/spec/unit/resources/permission_target_spec.rb +0 -189
  72. data/spec/unit/resources/plugin_spec.rb +0 -25
  73. data/spec/unit/resources/repository_spec.rb +0 -217
  74. data/spec/unit/resources/system_spec.rb +0 -90
  75. data/spec/unit/resources/url_base_spec.rb +0 -53
  76. data/spec/unit/resources/user_spec.rb +0 -115
@@ -1,11 +0,0 @@
1
- module Artifactory
2
- module APIServer::StatusEndpoints
3
- def self.registered(app)
4
- app.get("/status/:code") { code.to_i }
5
- app.post("/status/:code") { code.to_i }
6
- app.patch("/status/:code") { code.to_i }
7
- app.put("/status/:code") { code.to_i }
8
- app.delete("/status/:code") { code.to_i }
9
- end
10
- end
11
- end
@@ -1,104 +0,0 @@
1
- module Artifactory
2
- module APIServer::SystemEndpoints
3
- def self.registered(app)
4
- app.get("/api/system") do
5
- "This is some serious system info right here"
6
- end
7
-
8
- app.get("/api/system/ping") do
9
- "OK"
10
- end
11
-
12
- app.get("/api/system/configuration") do
13
- content_type "application/xml"
14
- <<-EOH.gsub(/^ {10}/, "")
15
- <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
16
- <config xsi:schemaLocation='http://www.jfrog.org/xsd/artifactory-v1_5_3.xsd'
17
- xmlns='http://artifactory.jfrog.org/xsd/1.5.3'
18
- xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
19
- <offlineMode>false</offlineMode>
20
- <repoLayouts>
21
- <repoLayout>
22
- <name>maven-2-default</name>
23
- <artifactPathPattern>[orgPath]/[module]/[baseRev](-[folderItegRev])/[module]-[baseRev](-[fileItegRev])(-[classifier]).[ext]</artifactPathPattern>
24
- <distinctiveDescriptorPathPattern>true</distinctiveDescriptorPathPattern>
25
- <descriptorPathPattern>[orgPath]/[module]/[baseRev](-[folderItegRev])/[module]-[baseRev](-[fileItegRev])(-[classifier]).pom</descriptorPathPattern>
26
- <folderIntegrationRevisionRegExp>SNAPSHOT</folderIntegrationRevisionRegExp>
27
- <fileIntegrationRevisionRegExp>SNAPSHOT|(?:(?:[0-9]{8}.[0-9]{6})-(?:[0-9]+))</fileIntegrationRevisionRegExp>
28
- </repoLayout>
29
- <repoLayout>
30
- <name>gradle-default</name>
31
- <artifactPathPattern>[orgPath]/[module]/[baseRev](-[folderItegRev])/[module]-[baseRev](-[fileItegRev])(-[classifier]).[ext]</artifactPathPattern>
32
- <distinctiveDescriptorPathPattern>true</distinctiveDescriptorPathPattern>
33
- <descriptorPathPattern>[orgPath]/[module]/[baseRev](-[folderItegRev])/[module]-[baseRev](-[fileItegRev])(-[classifier]).pom</descriptorPathPattern>
34
- <folderIntegrationRevisionRegExp>SNAPSHOT</folderIntegrationRevisionRegExp>
35
- <fileIntegrationRevisionRegExp>SNAPSHOT|(?:(?:[0-9]{8}.[0-9]{6})-(?:[0-9]+))</fileIntegrationRevisionRegExp>
36
- </repoLayout>
37
- </repoLayouts>
38
- <urlBase>http://33.33.33.20/artifactory</urlBase>
39
- <mailServer>
40
- <enabled>true</enabled>
41
- <host>smtp.gmail.com</host>
42
- <port>25</port>
43
- <username>us@example.com</username>
44
- <password>ihopethisisnotyourpassword</password>
45
- <from>artifactory@example.com</from>
46
- <subjectPrefix>[Artifactory]</subjectPrefix>
47
- <tls>true</tls>
48
- <ssl>false</ssl>
49
- <artifactoryUrl>http://33.33.33.20/artifactory</artifactoryUrl>
50
- </mailServer>
51
- <security>
52
- <ldapSettings>
53
- <ldapSetting>
54
- <key>example-ldap</key>
55
- <enabled>true</enabled>
56
- <ldapUrl>ldap://localhost/DC=examplecorp,DC=com</ldapUrl>
57
- <search>
58
- <searchFilter>sAMAccountName={0}</searchFilter>
59
- <searchBase>OU=Domain Users</searchBase>
60
- <searchSubTree>true</searchSubTree>
61
- <managerDn>CN=ldapbind,OU=Employees,OU=Domain Users,DC=examplecorp,DC=com</managerDn>
62
- <managerPassword>ldappassword</managerPassword>
63
- </search>
64
- <autoCreateUser>false</autoCreateUser>
65
- <emailAttribute>mail</emailAttribute>
66
- </ldapSetting>
67
- </ldapSettings>
68
- </security>
69
- <backups>
70
- <backup>
71
- <key>backup-daily</key>
72
- <enabled>true</enabled>
73
- <cronExp>0 0 2 ? * MON-FRI</cronExp>
74
- <retentionPeriodHours>0</retentionPeriodHours>
75
- <createArchive>false</createArchive>
76
- <excludedRepositories/>
77
- <sendMailOnError>true</sendMailOnError>
78
- <excludeBuilds>false</excludeBuilds>
79
- </backup>
80
- </backups>
81
- </config>
82
- EOH
83
- end
84
-
85
- app.post("/api/system/configuration") do
86
- # Just echo the response we got back, since it seems that's what a real
87
- # Artifactory server does...
88
- request.body.read
89
- end
90
-
91
- app.get("/api/system/version") do
92
- content_type "application/vnd.org.jfrog.artifactory.system.Version+json"
93
- JSON.generate({
94
- "version" => "3.1.0",
95
- "revision" => "30062",
96
- "addons" => %w{
97
- ldap
98
- license
99
- yum},
100
- })
101
- end
102
- end
103
- end
104
- end
@@ -1,59 +0,0 @@
1
- module Artifactory
2
- module APIServer::UserEndpoints
3
- def self.registered(app)
4
- app.get("/api/security/users") do
5
- content_type "application/vnd.org.jfrog.artifactory.security.Users+json"
6
- JSON.fast_generate([
7
- {
8
- "name" => "sethvargo",
9
- "uri" => server_url.join("/api/security/users/sethvargo"),
10
- },
11
- {
12
- "name" => "yzl",
13
- "uri" => server_url.join("/api/security/users/yzl"),
14
- },
15
- ])
16
- end
17
-
18
- app.get("/api/security/users/sethvargo") do
19
- content_type "application/vnd.org.jfrog.artifactory.security.User+json"
20
- JSON.fast_generate(
21
- "admin" => false,
22
- "email" => "sethvargo@gmail.com",
23
- "groups" => ["admin"],
24
- "internalPasswordDisabled" => true,
25
- "lastLoggedIn" => nil,
26
- "name" => "sethvargo",
27
- "profileUpdatable" => true,
28
- "realm" => "artifactory"
29
- )
30
- end
31
-
32
- app.get("/api/security/users/yzl") do
33
- content_type "application/vnd.org.jfrog.artifactory.security.User+json"
34
- JSON.fast_generate(
35
- "admin" => true,
36
- "email" => "yvonne@getchef.com",
37
- "groups" => ["admin"],
38
- "internalPasswordDisabled" => true,
39
- "lastLoggedIn" => nil,
40
- "name" => "yzl",
41
- "profileUpdatable" => true,
42
- "realm" => "crowd"
43
- )
44
- end
45
-
46
- app.put("/api/security/users/:name") do
47
- return 415 unless request.content_type == "application/vnd.org.jfrog.artifactory.security.User+json"
48
-
49
- # Attempt to parse the response; if this succeeds, all is well...
50
- JSON.parse(request.body.read)
51
- nil
52
- end
53
-
54
- app.delete("/api/security/users/:name") do
55
- nil
56
- end
57
- end
58
- end
59
- end
@@ -1,73 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Artifactory do
4
- it "sets the default values" do
5
- Artifactory::Configurable.keys.each do |key|
6
- value = Artifactory::Defaults.send(key)
7
- expect(Artifactory.instance_variable_get(:"@#{key}")).to eq(value)
8
- end
9
- end
10
-
11
- describe ".client" do
12
- it "creates an Artifactory::Client" do
13
- expect(Artifactory.client).to be_a(Artifactory::Client)
14
- end
15
-
16
- it "caches the client when the same options are passed" do
17
- expect(Artifactory.client).to eq(Artifactory.client)
18
- end
19
-
20
- it "returns a fresh client when options are not the same" do
21
- original_client = Artifactory.client
22
-
23
- # Change settings
24
- Artifactory.username = "admin"
25
- new_client = Artifactory.client
26
-
27
- # Get it one more tmie
28
- current_client = Artifactory.client
29
-
30
- expect(original_client).to_not eq(new_client)
31
- expect(new_client).to eq(current_client)
32
- end
33
- end
34
-
35
- describe ".configure" do
36
- Artifactory::Configurable.keys.each do |key|
37
- it "sets the #{key.to_s.tr('_', ' ')}" do
38
- Artifactory.configure do |config|
39
- config.send("#{key}=", key)
40
- end
41
-
42
- expect(Artifactory.instance_variable_get(:"@#{key}")).to eq(key)
43
- end
44
- end
45
- end
46
-
47
- describe ".method_missing" do
48
- context "when the client responds to the method" do
49
- let(:client) { double(:client) }
50
- before { allow(Artifactory).to receive(:client).and_return(client) }
51
-
52
- it "delegates the method to the client" do
53
- allow(client).to receive(:bacon).and_return("awesome")
54
- expect { Artifactory.bacon }.to_not raise_error
55
- end
56
- end
57
-
58
- context "when the client does not respond to the method" do
59
- it "calls super" do
60
- expect { Artifactory.bacon }.to raise_error(NoMethodError)
61
- end
62
- end
63
- end
64
-
65
- describe ".respond_to_missing?" do
66
- let(:client) { double(:client) }
67
- before { allow(Artifactory).to receive(:client).and_return(client) }
68
-
69
- it "delegates to the client" do
70
- expect { Artifactory.respond_to_missing?(:foo) }.to_not raise_error
71
- end
72
- end
73
- end
@@ -1,132 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Artifactory
4
- describe Client do
5
- let(:client) { subject }
6
-
7
- context "configuration" do
8
- it "is a configurable object" do
9
- expect(client).to be_a(Configurable)
10
- end
11
-
12
- it "users the default configuration" do
13
- Defaults.options.each do |key, value|
14
- expect(client.send(key)).to eq(value)
15
- end
16
- end
17
-
18
- it "uses the values in the initializer" do
19
- client = described_class.new(username: "admin")
20
- expect(client.username).to eq("admin")
21
- end
22
-
23
- it "can be modified after initialization" do
24
- expect(client.username).to eq(Defaults.username)
25
- client.username = "admin"
26
- expect(client.username).to eq("admin")
27
- end
28
- end
29
-
30
- describe ".proxy" do
31
- before { described_class.proxy(Resource::Artifact) }
32
-
33
- it "defines a new method" do
34
- expect(described_class).to be_method_defined(:artifact_search)
35
- end
36
-
37
- it "delegates to the class, injecting the client" do
38
- allow(Resource::Artifact).to receive(:search)
39
- expect(Resource::Artifact).to receive(:search).with(client: subject)
40
- subject.artifact_search
41
- end
42
- end
43
-
44
- describe "#get" do
45
- it "delegates to the #request method" do
46
- expect(subject).to receive(:request).with(:get, "/foo", {}, {})
47
- subject.get("/foo")
48
- end
49
-
50
- context "called with a block" do
51
- it "yields the response in chunks" do
52
- expect(subject).to receive(:request).with(:get, "/foo", {}, {}) { |&block| block.call("Chunked Body") }
53
- expect { |chunk| subject.get("/foo", &chunk) }.to yield_with_args("Chunked Body")
54
- end
55
- end
56
- end
57
-
58
- describe "#post" do
59
- let(:data) { double }
60
-
61
- it "delegates to the #request method" do
62
- expect(subject).to receive(:request).with(:post, "/foo", data, {})
63
- subject.post("/foo", data)
64
- end
65
- end
66
-
67
- describe "#put" do
68
- let(:data) { double }
69
-
70
- it "delegates to the #request method" do
71
- expect(subject).to receive(:request).with(:put, "/foo", data, {})
72
- subject.put("/foo", data)
73
- end
74
- end
75
-
76
- describe "#patch" do
77
- let(:data) { double }
78
-
79
- it "delegates to the #request method" do
80
- expect(subject).to receive(:request).with(:patch, "/foo", data, {})
81
- subject.patch("/foo", data)
82
- end
83
- end
84
-
85
- describe "#delete" do
86
- it "delegates to the #request method" do
87
- expect(subject).to receive(:request).with(:delete, "/foo", {}, {})
88
- subject.delete("/foo")
89
- end
90
- end
91
-
92
- describe "#request" do
93
- context "when the response is a 400" do
94
- before { stub_request(:get, /.+/).to_return(status: 5000, body: "No!") }
95
-
96
- it "raises an HTTPError error" do
97
- expect { subject.request(:get, "/") }.to raise_error(Error::HTTPError)
98
- end
99
- end
100
-
101
- context "called with a block" do
102
- before { stub_request(:get, /.+/).to_return(status: 200, body: "Chunked Body") }
103
-
104
- it "yields the response in chunks" do
105
- subject.request(:get, "/foo") do |chunk|
106
- expect(chunk).to eq("Chunked Body")
107
- end
108
- end
109
- end
110
-
111
- context "application/json response with an empty body" do
112
- before { stub_request(:get, /.+/).to_return(status: 200, headers: { "Content-Type" => "application/json" }, body: "") }
113
-
114
- it "should not raise an error" do
115
- expect { subject.request(:get, "/foo") }.to_not raise_error(TypeError)
116
- end
117
- end
118
- end
119
-
120
- describe "#to_query_string" do
121
- it 'converts spaces to "+" characters' do
122
- params = { user: "Seth Chisamore" }
123
- expect(subject.to_query_string(params)).to eq("user=Seth+Chisamore")
124
- end
125
-
126
- it 'converts "+" to "%2B"' do
127
- params = { version: "12.0.0-alpha.1+20140826080510.git.50.f5ff271" }
128
- expect(subject.to_query_string(params)).to eq("version=12.0.0-alpha.1%2B20140826080510.git.50.f5ff271")
129
- end
130
- end
131
- end
132
- end
@@ -1,608 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Artifactory
4
- describe Resource::Artifact do
5
- let(:client) { double(:client) }
6
- let(:endpoint_host) { "http://33.33.33.11" }
7
- let(:endpoint) { "#{endpoint_host}/" }
8
-
9
- before(:each) do
10
- allow(Artifactory).to receive(:client).and_return(client)
11
- allow(client).to receive(:get).and_return(response) if defined?(response)
12
- end
13
-
14
- describe ".search" do
15
- let(:response) { { "results" => [] } }
16
-
17
- it "calls /api/search/artifact" do
18
- expect(client).to receive(:get).with("/api/search/artifact", {}).once
19
- described_class.search
20
- end
21
-
22
- it "slices the correct parameters" do
23
- expect(client).to receive(:get).with("/api/search/artifact",
24
- name: "name",
25
- repos: "repo"
26
- ).once
27
- described_class.search(
28
- name: "name",
29
- repos: "repo",
30
- fizz: "foo"
31
- )
32
- end
33
-
34
- it "returns an array of objects" do
35
- expect(described_class.search).to be_a(Array)
36
- end
37
- end
38
-
39
- describe "#upload" do
40
- let(:client) { double(put: {}) }
41
- let(:local_path) { "/local/path" }
42
- let(:file) { double(File) }
43
-
44
- subject { described_class.new(client: client, local_path: local_path) }
45
-
46
- before do
47
- allow(File).to receive(:new).with(/\A(\w:)?#{local_path}\z/).and_return(file)
48
- end
49
-
50
- context "when the artifact is a file path" do
51
- it "PUTs the file at the path to the server" do
52
- expect(client).to receive(:put).with("libs-release-local/remote/path", file, {})
53
- subject.upload("libs-release-local", "/remote/path")
54
- end
55
- end
56
-
57
- context "when the md5 is available" do
58
- subject { described_class.new(client: client, local_path: local_path, checksums: { "md5" => "ABCDEF123456" } ) }
59
-
60
- it "PUTs the file with the checksum headers set" do
61
- expect(client).to receive(:put).with("libs-release-local/remote/path", file, { "X-Checksum-Md5" => "ABCDEF123456" } )
62
- subject.upload("libs-release-local", "/remote/path")
63
- end
64
- end
65
-
66
- context "when the sha1 is available" do
67
- subject { described_class.new(client: client, local_path: local_path, checksums: { "sha1" => "SHA1" } ) }
68
-
69
- it "PUTs the file with the checksum headers set" do
70
- expect(client).to receive(:put).with("libs-release-local/remote/path", file, { "X-Checksum-Sha1" => "SHA1" } )
71
- subject.upload("libs-release-local", "/remote/path")
72
- end
73
- end
74
-
75
- context "when matrix properties are given" do
76
- it "converts the hash into matrix properties" do
77
- expect(client).to receive(:put).with("libs-release-local;branch=master;user=Seth/remote/path", file, {})
78
-
79
- subject.upload("libs-release-local", "/remote/path",
80
- branch: "master",
81
- user: "Seth"
82
- )
83
- end
84
-
85
- it 'converts spaces to "+" characters' do
86
- expect(client).to receive(:put).with("libs-release-local;user=Seth+Vargo/remote/path", file, {})
87
-
88
- subject.upload("libs-release-local", "/remote/path",
89
- user: "Seth Vargo"
90
- )
91
- end
92
-
93
- it 'converts "+" to "%2B"' do
94
- expect(client).to receive(:put).with("libs-release-local;version=12.0.0-alpha.1%2B20140826080510.git.50.f5ff271/remote/path", file, {})
95
-
96
- subject.upload("libs-release-local", "/remote/path",
97
- version: "12.0.0-alpha.1+20140826080510.git.50.f5ff271"
98
- )
99
- end
100
- end
101
-
102
- context "when custom headers are given" do
103
- it "passes the headers to the client" do
104
- headers = { "Content-Type" => "text/plain" }
105
- expect(client).to receive(:put).with("libs-release-local/remote/path", file, headers)
106
-
107
- subject.upload("libs-release-local", "/remote/path", {}, headers)
108
- end
109
- end
110
- end
111
-
112
- describe "#upload_checksum" do
113
- it "uploads checksum.sha1" do
114
- value = "ABCD1234"
115
-
116
- tempfile = double("Tempfile").as_null_object
117
- expect(Tempfile).to receive(:new).with("checksum.sha1") { tempfile }
118
- expect(tempfile).to receive(:write).with(value).once
119
- expect(client).to receive(:put).with(
120
- "libs-release-local/remote/path.sha1",
121
- tempfile
122
- )
123
- subject.upload_checksum("libs-release-local", "/remote/path", "sha1", value)
124
- end
125
- end
126
-
127
- describe "#upload_with_checksum" do
128
- it "delegates to #upload" do
129
- expect(subject).to receive(:upload).with(
130
- "libs-release-local",
131
- "/remote/path",
132
- { branch: "master" },
133
- {
134
- "X-Checksum-Deploy" => true,
135
- "X-Checksum-Sha1" => "ABCD1234",
136
- }
137
- )
138
- subject.upload_with_checksum("libs-release-local", "/remote/path", "ABCD1234",
139
- { branch: "master" }
140
- )
141
- end
142
- end
143
-
144
- describe "#upload_from_archive" do
145
- it "delegates to #upload" do
146
- expect(subject).to receive(:upload).with(
147
- "libs-release-local",
148
- "/remote/path",
149
- {},
150
- { "X-Explode-Archive" => true }
151
- )
152
- subject.upload_from_archive("libs-release-local", "/remote/path")
153
- end
154
-
155
- it "receives empty response" do
156
- file = double(File)
157
- allow(File).to receive(:new).and_return( file )
158
- expect(client).to receive(:put).with(
159
- "libs-release-local/remote/path",
160
- file,
161
- { "X-Explode-Archive" => true }
162
- )
163
- subject.local_path = "/local/path"
164
- subject.upload_from_archive("libs-release-local", "/remote/path")
165
- end
166
-
167
- end
168
-
169
- describe ".gavc_search" do
170
- let(:response) { { "results" => [] } }
171
-
172
- it "calls /api/search/gavc" do
173
- expect(client).to receive(:get).with("/api/search/gavc", {}).once
174
- described_class.gavc_search
175
- end
176
-
177
- it "renames the parameters" do
178
- expect(client).to receive(:get).with("/api/search/gavc",
179
- g: "group",
180
- a: "name",
181
- v: "version",
182
- c: "classifier"
183
- ).once
184
- described_class.gavc_search(
185
- group: "group",
186
- name: "name",
187
- version: "version",
188
- classifier: "classifier"
189
- )
190
- end
191
-
192
- it "slices the correct parameters" do
193
- expect(client).to receive(:get).with("/api/search/gavc",
194
- g: "group",
195
- a: "name"
196
- ).once
197
- described_class.gavc_search(
198
- group: "group",
199
- name: "name",
200
- fizz: "foo"
201
- )
202
- end
203
-
204
- it "returns an array of objects" do
205
- expect(described_class.gavc_search).to be_a(Array)
206
- end
207
- end
208
-
209
- describe ".property_search" do
210
- let(:response) { { "results" => [] } }
211
-
212
- it "calls /api/search/prop" do
213
- expect(client).to receive(:get).with("/api/search/prop", {}).once
214
- described_class.property_search
215
- end
216
-
217
- it "passes all the parameters" do
218
- expect(client).to receive(:get).with("/api/search/prop",
219
- p1: "v1",
220
- p2: "v2"
221
- ).once
222
- described_class.property_search(
223
- p1: "v1",
224
- p2: "v2"
225
- )
226
- end
227
-
228
- it "returns an array of objects" do
229
- expect(described_class.property_search).to be_a(Array)
230
- end
231
- end
232
-
233
- describe ".checksum_search" do
234
- let(:response) { { "results" => [] } }
235
-
236
- it "calls /api/search/checksum" do
237
- expect(client).to receive(:get).with("/api/search/checksum", {}).once
238
- described_class.checksum_search
239
- end
240
-
241
- it "slices the correct parameters" do
242
- expect(client).to receive(:get).with("/api/search/checksum",
243
- md5: "MD5123",
244
- sha1: "SHA456"
245
- ).once
246
- described_class.checksum_search(
247
- md5: "MD5123",
248
- sha1: "SHA456",
249
- fizz: "foo"
250
- )
251
- end
252
-
253
- it "returns an array of objects" do
254
- expect(described_class.checksum_search).to be_a(Array)
255
- end
256
- end
257
-
258
- describe ".usage_search" do
259
- let(:response) { { "results" => [] } }
260
-
261
- it "calls /api/search/usage" do
262
- expect(client).to receive(:get).with("/api/search/usage", {}).once
263
- described_class.usage_search
264
- end
265
-
266
- it "slices the correct parameters" do
267
- expect(client).to receive(:get).with("/api/search/usage",
268
- notUsedSince: 1414800000000,
269
- createdBefore: 1414871200000
270
- ).once
271
- described_class.usage_search(
272
- notUsedSince: 1414800000000,
273
- createdBefore: 1414871200000,
274
- fizz: "foo"
275
- )
276
- end
277
-
278
- it "returns an array of objects" do
279
- expect(described_class.usage_search).to be_a(Array)
280
- end
281
- end
282
-
283
- describe ".creation_search" do
284
- let(:response) { { "results" => [] } }
285
-
286
- it "calls /api/search/creation" do
287
- expect(client).to receive(:get).with("/api/search/creation", {}).once
288
- described_class.creation_search
289
- end
290
-
291
- it "slices the correct parameters" do
292
- expect(client).to receive(:get).with("/api/search/creation",
293
- from: 1414800000000,
294
- to: 1414871200000
295
- ).once
296
- described_class.creation_search(
297
- from: 1414800000000,
298
- to: 1414871200000,
299
- fizz: "foo"
300
- )
301
- end
302
-
303
- it "returns an array of objects" do
304
- expect(described_class.creation_search).to be_a(Array)
305
- end
306
- end
307
-
308
- describe ".versions" do
309
- let(:response) { { "results" => [] } }
310
-
311
- it "calls /api/search/versions" do
312
- expect(client).to receive(:get).with("/api/search/versions", {}).once
313
- described_class.versions
314
- end
315
-
316
- it "renames the parameters" do
317
- expect(client).to receive(:get).with("/api/search/versions",
318
- g: "group",
319
- a: "name",
320
- v: "version"
321
- ).once
322
- described_class.versions(
323
- group: "group",
324
- name: "name",
325
- version: "version"
326
- )
327
- end
328
-
329
- it "slices the correct parameters" do
330
- expect(client).to receive(:get).with("/api/search/versions",
331
- g: "group",
332
- a: "name"
333
- ).once
334
- described_class.versions(
335
- group: "group",
336
- name: "name",
337
- fizz: "foo"
338
- )
339
- end
340
-
341
- it "returns an array of objects" do
342
- expect(described_class.versions).to be_a(Array)
343
- end
344
-
345
- it "returns an empty array when the server responses with a 404" do
346
- allow(client).to receive(:get).and_raise(Error::HTTPError.new("status" => 404))
347
-
348
- result = described_class.versions
349
- expect(result).to be_a(Array)
350
- expect(result).to be_empty
351
- end
352
- end
353
-
354
- describe ".latest_version" do
355
- let(:response) { "1.2-SNAPSHOT" }
356
-
357
- it "calls /api/search/latestVersion" do
358
- expect(client).to receive(:get).with("/api/search/latestVersion", {}).once
359
- described_class.latest_version
360
- end
361
-
362
- it "renames the parameters" do
363
- expect(client).to receive(:get).with("/api/search/latestVersion",
364
- g: "group",
365
- a: "name",
366
- v: "version"
367
- ).once
368
- described_class.latest_version(
369
- group: "group",
370
- name: "name",
371
- version: "version"
372
- )
373
- end
374
-
375
- it "slices the correct parameters" do
376
- expect(client).to receive(:get).with("/api/search/latestVersion",
377
- g: "group",
378
- a: "name"
379
- ).once
380
- described_class.latest_version(
381
- group: "group",
382
- name: "name",
383
- fizz: "foo"
384
- )
385
- end
386
-
387
- it "returns the latest version" do
388
- expect(described_class.latest_version).to eq("1.2-SNAPSHOT")
389
- end
390
-
391
- it "returns an nil when the server responses with a 404" do
392
- allow(client).to receive(:get).and_raise(Error::HTTPError.new("status" => 404))
393
-
394
- expect(described_class.latest_version).to be_nil
395
- end
396
- end
397
-
398
- describe ".from_url" do
399
- let(:response) { {} }
400
-
401
- it "constructs a new instance from the result" do
402
- expect(client).to receive(:endpoint).and_return(endpoint)
403
- expect(described_class).to receive(:from_hash).once
404
- described_class.from_url("/some/artifact/path.deb")
405
- end
406
- end
407
-
408
- describe ".from_hash" do
409
- let(:hash) do
410
- {
411
- "uri" => "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom",
412
- "downloadUri" => "http://localhost:8080/artifactory/libs-release-local/org/acme/lib/ver/lib-ver.pom",
413
- "repo" => "libs-release-local",
414
- "path" => "/org/acme/lib/ver/lib-ver.pom",
415
- "remoteUrl" => "http://some-remote-repo/mvn/org/acme/lib/ver/lib-ver.pom",
416
- "created" => "2014-01-01 10:00 UTC",
417
- "createdBy" => "userY",
418
- "lastModified" => "2014-01-01 11:00 UTC",
419
- "modifiedBy" => "userX",
420
- "lastUpdated" => "2014-01-01 12:00 UTC",
421
- "size" => "1024",
422
- "mimeType" => "application/pom+xml",
423
- "checksums" => { "md5" => "MD5123", "sha1" => "SHA456" },
424
- "originalChecksums" => { "md5" => "MD5123", "sha1" => "SHA456" },
425
- }
426
- end
427
-
428
- it "creates a new instance" do
429
- instance = described_class.from_hash(hash)
430
- expect(instance).to be_a(described_class)
431
- expect(instance.uri).to eq("http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom")
432
- expect(instance.client).to be(client)
433
- expect(instance.created).to eq(Time.parse("2014-01-01 10:00 UTC"))
434
- expect(instance.download_uri).to eq("http://localhost:8080/artifactory/libs-release-local/org/acme/lib/ver/lib-ver.pom")
435
- expect(instance.last_modified).to eq(Time.parse("2014-01-01 11:00 UTC"))
436
- expect(instance.last_updated).to eq(Time.parse("2014-01-01 12:00 UTC"))
437
- expect(instance.md5).to eq("MD5123")
438
- expect(instance.mime_type).to eq("application/pom+xml")
439
- expect(instance.sha1).to eq("SHA456")
440
- expect(instance.size).to eq(1024)
441
- end
442
- end
443
-
444
- describe "#copy" do
445
- let(:destination) { "/to/here" }
446
- let(:options) { Hash.new }
447
- before { allow(subject).to receive(:copy_or_move) }
448
-
449
- it "delegates to #copy_or_move" do
450
- expect(subject).to receive(:copy_or_move).with(:copy, destination, options)
451
- subject.copy(destination, options)
452
- end
453
- end
454
-
455
- describe "#delete" do
456
- let(:client) { double }
457
-
458
- it "sends DELETE to the client" do
459
- subject.client = client
460
- subject.download_uri = "/artifact.deb"
461
-
462
- expect(client).to receive(:delete)
463
- subject.delete
464
- end
465
- end
466
-
467
- describe "#move" do
468
- let(:destination) { "/to/here" }
469
- let(:options) { Hash.new }
470
- before { allow(subject).to receive(:copy_or_move) }
471
-
472
- it "delegates to #copy_or_move" do
473
- expect(subject).to receive(:copy_or_move).with(:move, destination, options)
474
- subject.move(destination, options)
475
- end
476
- end
477
-
478
- describe "#properties" do
479
- let(:properties) do
480
- { "artifactory.licenses" => ["Apache-2.0"] }
481
- end
482
- let(:response) do
483
- { "properties" => properties }
484
- end
485
-
486
- let(:client) { double(get: response) }
487
- let(:relative_path) { "/api/storage/some-repo/path/artifact.deb" }
488
- let(:artifact_uri) { File.join("http://33.33.33.11", relative_path) }
489
-
490
- let(:property_set_path) { "#{relative_path}?properties=;author=J%C3%B6rg;status=public" }
491
- let(:new_properties) { { author: "Jörg", "status" => "public" } }
492
- let(:client) { double(put: nil ) }
493
-
494
- before do
495
- subject.client = client
496
- subject.uri = artifact_uri
497
- end
498
-
499
- it "gets the properties from the server" do
500
- expect(client).to receive(:get).with(relative_path, properties: nil).once
501
- expect(subject.properties).to eq(properties)
502
- end
503
-
504
- it "caches the response" do
505
- subject.properties
506
- expect(subject.instance_variable_get(:@properties)).to eq(properties)
507
- end
508
-
509
- it "sets the properties on the server" do
510
- expect(client).to receive(:put).with(property_set_path, nil).once
511
- subject.properties(new_properties)
512
- end
513
-
514
- it "updates the chache" do
515
- expect(subject).to receive(:get_properties).with(true).once
516
- subject.properties(new_properties)
517
- end
518
- end
519
-
520
- describe "#compliance" do
521
- let(:compliance) do
522
- { "licenses" => [{ "name" => "LGPL v3" }] }
523
- end
524
- let(:client) { double(get: compliance) }
525
- let(:uri) { "/artifact.deb" }
526
-
527
- before do
528
- subject.client = client
529
- subject.uri = uri
530
- end
531
-
532
- it "gets the compliance from the server" do
533
- expect(client).to receive(:get).with("/api/compliance/artifact.deb").once
534
- expect(subject.compliance).to eq(compliance)
535
- end
536
-
537
- it "caches the response" do
538
- subject.compliance
539
- expect(subject.instance_variable_get(:@compliance)).to eq(compliance)
540
- end
541
- end
542
-
543
- describe "#download" do
544
- it "download content to directory" do
545
- Dir.mktmpdir("artifact_download") do |tmpdir|
546
- subject.download_uri = "/artifact.deb"
547
-
548
- expect(client).to receive(:get) { "some content" }
549
- subject.download(tmpdir)
550
- expect(Dir.entries(tmpdir)).to include("artifact.deb")
551
- end
552
- end
553
-
554
- it "download content to directory with filename" do
555
- Dir.mktmpdir("artifact_download") do |tmpdir|
556
- subject.download_uri = "/artifact.deb"
557
-
558
- expect(client).to receive(:get) { "some content" }
559
- subject.download(tmpdir, { filename: "foobar.deb" })
560
- expect(Dir.entries(tmpdir)).to include("foobar.deb")
561
- end
562
- end
563
-
564
- it "writes the file in chunks" do
565
- Dir.mktmpdir("artifact_download") do |tmpdir|
566
- subject.download_uri = "/artifact.deb"
567
-
568
- expect(client).to receive(:get).and_yield("some content")
569
-
570
- file = double("file")
571
- expect(File).to receive(:open).with(File.join(tmpdir, "artifact.deb"), "wb").and_yield(file)
572
- expect(file).to receive(:write).with("some content")
573
-
574
- subject.download(tmpdir)
575
- end
576
- end
577
- end
578
-
579
- describe "#relative_path" do
580
- before { described_class.send(:public, :relative_path) }
581
-
582
- it "parses the relative path" do
583
- subject.uri = "/api/storage/foo/bar/zip"
584
- expect(subject.relative_path).to eq("/foo/bar/zip")
585
- end
586
- end
587
-
588
- describe "#copy_or_move" do
589
- let(:client) { double }
590
- before do
591
- described_class.send(:public, :copy_or_move)
592
-
593
- subject.client = client
594
- subject.uri = "/api/storage/foo/bar/artifact.deb"
595
- end
596
-
597
- it "sends POST to the client with parsed params" do
598
- expect(client).to receive(:post).with("/api/move/foo/bar/artifact.deb?to=/to/path", {})
599
- subject.copy_or_move(:move, "/to/path")
600
- end
601
-
602
- it "adds the correct parameters to the request" do
603
- expect(client).to receive(:post).with("/api/move/foo/bar/artifact.deb?to=/to/path&failFast=1&dry=1", {})
604
- subject.copy_or_move(:move, "/to/path", fail_fast: true, dry_run: true)
605
- end
606
- end
607
- end
608
- end