artifactory 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/lib/artifactory.rb +13 -9
- data/lib/artifactory/client.rb +16 -3
- data/lib/artifactory/errors.rb +1 -2
- data/lib/artifactory/resources/artifact.rb +56 -27
- data/lib/artifactory/resources/backup.rb +104 -0
- data/lib/artifactory/resources/base.rb +47 -0
- data/lib/artifactory/resources/layout.rb +1 -50
- data/lib/artifactory/resources/ldap_setting.rb +105 -0
- data/lib/artifactory/resources/mail_server.rb +61 -0
- data/lib/artifactory/resources/repository.rb +11 -14
- data/lib/artifactory/resources/url_base.rb +74 -0
- data/lib/artifactory/util.rb +41 -0
- data/lib/artifactory/version.rb +1 -1
- data/spec/integration/resources/backup.rb +22 -0
- data/spec/integration/resources/build_spec.rb +1 -3
- data/spec/integration/resources/group_spec.rb +2 -2
- data/spec/integration/resources/ldap_setting_spec.rb +22 -0
- data/spec/integration/resources/mail_server_spec.rb +22 -0
- data/spec/integration/resources/repository_spec.rb +1 -1
- data/spec/integration/resources/system_spec.rb +1 -1
- data/spec/integration/resources/url_base_spec.rb +22 -0
- data/spec/integration/resources/user_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/api_server/system_endpoints.rb +44 -1
- data/spec/unit/artifactory_spec.rb +3 -3
- data/spec/unit/client_spec.rb +1 -1
- data/spec/unit/resources/artifact_spec.rb +18 -36
- data/spec/unit/resources/backup_spec.rb +61 -0
- data/spec/unit/resources/base_spec.rb +3 -3
- data/spec/unit/resources/build_spec.rb +3 -3
- data/spec/unit/resources/group_spec.rb +6 -6
- data/spec/unit/resources/layout_spec.rb +4 -4
- data/spec/unit/resources/ldap_setting_spec.rb +65 -0
- data/spec/unit/resources/mail_server_spec.rb +57 -0
- data/spec/unit/resources/plugin_spec.rb +2 -2
- data/spec/unit/resources/repository_spec.rb +19 -27
- data/spec/unit/resources/system_spec.rb +6 -6
- data/spec/unit/resources/url_base_spec.rb +53 -0
- data/spec/unit/resources/user_spec.rb +8 -8
- metadata +23 -3
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Artifactory
|
4
|
+
describe Resource::URLBase, :integration do
|
5
|
+
describe '.all' do
|
6
|
+
it 'returns an array of UrlBases' do
|
7
|
+
results = described_class.all
|
8
|
+
expect(results).to be_a(Array)
|
9
|
+
expect(results.first).to be_a(described_class)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.find' do
|
14
|
+
it 'finds a urlBase by url' do
|
15
|
+
base = described_class.find('http://33.33.33.20/artifactory')
|
16
|
+
|
17
|
+
expect(base).to be_a(described_class)
|
18
|
+
expect(base.url_base).to eq('http://33.33.33.20/artifactory')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -31,14 +31,14 @@ module Artifactory
|
|
31
31
|
describe '#delete' do
|
32
32
|
it 'deletes the user from the server' do
|
33
33
|
sethvargo = described_class.find('sethvargo')
|
34
|
-
expect(sethvargo.delete).to
|
34
|
+
expect(sethvargo.delete).to be_truthy
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#save' do
|
39
39
|
it 'saves the user to the server' do
|
40
40
|
user = described_class.new(name: 'schisamo')
|
41
|
-
expect(user.save).to
|
41
|
+
expect(user.save).to be_truthy
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,7 +20,6 @@ RSpec.configure do |config|
|
|
20
20
|
# is focused, then all tests are executed.
|
21
21
|
config.filter_run(focus: true)
|
22
22
|
config.run_all_when_everything_filtered = true
|
23
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
24
23
|
|
25
24
|
# Stuff to do on each run
|
26
25
|
config.before(:each) { Artifactory.reset! }
|
@@ -35,7 +35,50 @@ module Artifactory
|
|
35
35
|
<fileIntegrationRevisionRegExp>SNAPSHOT|(?:(?:[0-9]{8}.[0-9]{6})-(?:[0-9]+))</fileIntegrationRevisionRegExp>
|
36
36
|
</repoLayout>
|
37
37
|
</repoLayouts>
|
38
|
-
|
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>
|
39
82
|
EOH
|
40
83
|
end
|
41
84
|
|
@@ -47,10 +47,10 @@ describe Artifactory do
|
|
47
47
|
describe '.method_missing' do
|
48
48
|
context 'when the client responds to the method' do
|
49
49
|
let(:client) { double(:client) }
|
50
|
-
before { Artifactory.
|
50
|
+
before { allow(Artifactory).to receive(:client).and_return(client) }
|
51
51
|
|
52
52
|
it 'delegates the method to the client' do
|
53
|
-
client.
|
53
|
+
allow(client).to receive(:bacon).and_return('awesome')
|
54
54
|
expect { Artifactory.bacon }.to_not raise_error
|
55
55
|
end
|
56
56
|
end
|
@@ -64,7 +64,7 @@ describe Artifactory do
|
|
64
64
|
|
65
65
|
describe '.respond_to_missing?' do
|
66
66
|
let(:client) { double(:client) }
|
67
|
-
before { Artifactory.
|
67
|
+
before { allow(Artifactory).to receive(:client).and_return(client) }
|
68
68
|
|
69
69
|
it 'delegates to the client' do
|
70
70
|
expect { Artifactory.respond_to_missing?(:foo) }.to_not raise_error
|
data/spec/unit/client_spec.rb
CHANGED
@@ -35,7 +35,7 @@ module Artifactory
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'delegates to the class, injecting the client' do
|
38
|
-
Resource::Artifact.
|
38
|
+
allow(Resource::Artifact).to receive(:search)
|
39
39
|
expect(Resource::Artifact).to receive(:search).with(client: subject)
|
40
40
|
subject.artifact_search
|
41
41
|
end
|
@@ -5,8 +5,8 @@ module Artifactory
|
|
5
5
|
let(:client) { double(:client) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
Artifactory.
|
9
|
-
client.
|
8
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
9
|
+
allow(client).to receive(:get).and_return(response) if defined?(response)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.search' do
|
@@ -35,39 +35,28 @@ module Artifactory
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#upload' do
|
38
|
-
let(:client)
|
39
|
-
|
40
|
-
|
41
|
-
end
|
38
|
+
let(:client) { double(put: {}) }
|
39
|
+
let(:local_path) { '/local/path' }
|
40
|
+
let(:file) { double(File) }
|
42
41
|
|
43
|
-
|
44
|
-
it 'PUTs the file to the server' do
|
45
|
-
file = double(file)
|
46
|
-
File.stub(:new).and_return(file)
|
47
|
-
expect(client).to receive(:put).with('libs-release-local/remote/path', file, {})
|
42
|
+
subject { described_class.new(client: client, local_path: local_path) }
|
48
43
|
|
49
|
-
|
50
|
-
|
44
|
+
before do
|
45
|
+
allow(File).to receive(:new).with(local_path).and_return(file)
|
51
46
|
end
|
52
47
|
|
53
48
|
context 'when the artifact is a file path' do
|
54
49
|
it 'PUTs the file at the path to the server' do
|
55
|
-
file = double(file)
|
56
|
-
path = '/fake/path'
|
57
|
-
File.stub(:new).with('/fake/path').and_return(file)
|
58
50
|
expect(client).to receive(:put).with('libs-release-local/remote/path', file, {})
|
59
|
-
|
60
|
-
subject.upload('libs-release-local', path, '/remote/path')
|
51
|
+
subject.upload('libs-release-local', '/remote/path')
|
61
52
|
end
|
62
53
|
end
|
63
54
|
|
64
55
|
context 'when matrix properties are given' do
|
65
56
|
it 'converts the hash into matrix properties' do
|
66
|
-
file = double(file)
|
67
|
-
File.stub(:new).and_return(file)
|
68
57
|
expect(client).to receive(:put).with('libs-release-local;branch=master;user=Seth%20Vargo/remote/path', file, {})
|
69
58
|
|
70
|
-
subject.upload('libs-release-local',
|
59
|
+
subject.upload('libs-release-local', '/remote/path',
|
71
60
|
branch: 'master',
|
72
61
|
user: 'Seth Vargo',
|
73
62
|
)
|
@@ -77,11 +66,9 @@ module Artifactory
|
|
77
66
|
context 'when custom headers are given' do
|
78
67
|
it 'passes the headers to the client' do
|
79
68
|
headers = { 'Content-Type' => 'text/plain' }
|
80
|
-
file = double(file)
|
81
|
-
File.stub(:new).and_return(file)
|
82
69
|
expect(client).to receive(:put).with('libs-release-local/remote/path', file, headers)
|
83
70
|
|
84
|
-
subject.upload('libs-release-local',
|
71
|
+
subject.upload('libs-release-local', '/remote/path', {}, headers)
|
85
72
|
end
|
86
73
|
end
|
87
74
|
end
|
@@ -90,7 +77,6 @@ module Artifactory
|
|
90
77
|
it 'delegates to #upload' do
|
91
78
|
expect(subject).to receive(:upload).with(
|
92
79
|
'libs-release-local',
|
93
|
-
'/local/file',
|
94
80
|
'/remote/path',
|
95
81
|
{ branch: 'master' },
|
96
82
|
{
|
@@ -98,8 +84,7 @@ module Artifactory
|
|
98
84
|
'X-Checksum-Sha1' => 'ABCD1234',
|
99
85
|
},
|
100
86
|
)
|
101
|
-
subject.upload_with_checksum('libs-release-local', '/
|
102
|
-
'ABCD1234',
|
87
|
+
subject.upload_with_checksum('libs-release-local', '/remote/path', 'ABCD1234',
|
103
88
|
{ branch: 'master' },
|
104
89
|
)
|
105
90
|
end
|
@@ -109,14 +94,11 @@ module Artifactory
|
|
109
94
|
it 'delegates to #upload' do
|
110
95
|
expect(subject).to receive(:upload).with(
|
111
96
|
'libs-release-local',
|
112
|
-
'/local/file',
|
113
97
|
'/remote/path',
|
114
98
|
{},
|
115
|
-
{
|
116
|
-
'X-Explode-Archive' => true,
|
117
|
-
},
|
99
|
+
{ 'X-Explode-Archive' => true },
|
118
100
|
)
|
119
|
-
subject.upload_from_archive('libs-release-local', '/
|
101
|
+
subject.upload_from_archive('libs-release-local', '/remote/path')
|
120
102
|
end
|
121
103
|
end
|
122
104
|
|
@@ -247,7 +229,7 @@ module Artifactory
|
|
247
229
|
end
|
248
230
|
|
249
231
|
it 'returns an empty array when the server responses with a 404' do
|
250
|
-
client.
|
232
|
+
allow(client).to receive(:get).and_raise(Error::HTTPError.new('status' => 404))
|
251
233
|
|
252
234
|
result = described_class.versions
|
253
235
|
expect(result).to be_a(Array)
|
@@ -293,7 +275,7 @@ module Artifactory
|
|
293
275
|
end
|
294
276
|
|
295
277
|
it 'returns an nil when the server responses with a 404' do
|
296
|
-
client.
|
278
|
+
allow(client).to receive(:get).and_raise(Error::HTTPError.new('status' => 404))
|
297
279
|
|
298
280
|
expect(described_class.latest_version).to be_nil
|
299
281
|
end
|
@@ -347,7 +329,7 @@ module Artifactory
|
|
347
329
|
describe '#copy' do
|
348
330
|
let(:destination) { '/to/here' }
|
349
331
|
let(:options) { Hash.new }
|
350
|
-
before { subject.
|
332
|
+
before { allow(subject).to receive(:copy_or_move) }
|
351
333
|
|
352
334
|
it 'delegates to #copy_or_move' do
|
353
335
|
expect(subject).to receive(:copy_or_move).with(:copy, destination, options)
|
@@ -370,7 +352,7 @@ module Artifactory
|
|
370
352
|
describe '#move' do
|
371
353
|
let(:destination) { '/to/here' }
|
372
354
|
let(:options) { Hash.new }
|
373
|
-
before { subject.
|
355
|
+
before { allow(subject).to receive(:copy_or_move) }
|
374
356
|
|
375
357
|
it 'delegates to #copy_or_move' do
|
376
358
|
expect(subject).to receive(:copy_or_move).with(:move, destination, options)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Artifactory
|
4
|
+
describe Resource::Backup do
|
5
|
+
let(:client) { double(:client) }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
9
|
+
allow(client).to receive(:get).and_return(response) if defined?(response)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.all' do
|
13
|
+
doc = <<-XML
|
14
|
+
<config>
|
15
|
+
<backups>
|
16
|
+
<backup>
|
17
|
+
<key>backup-daily</key>
|
18
|
+
</backup>
|
19
|
+
</backups>
|
20
|
+
</config>
|
21
|
+
XML
|
22
|
+
let(:xml) do
|
23
|
+
REXML::Document.new(doc)
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
allow(Resource::System).to receive(:configuration).and_return(xml)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the backup settings' do
|
31
|
+
expect(described_class.all).to be_a(Array)
|
32
|
+
expect(described_class.all.first).to be_a(described_class)
|
33
|
+
expect(described_class.all.first.key).to eq('backup-daily')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.find' do
|
38
|
+
doc = <<-XML
|
39
|
+
<config>
|
40
|
+
<backups>
|
41
|
+
<backup>
|
42
|
+
<key>backup-weekly</key>
|
43
|
+
</backup>
|
44
|
+
</backups>
|
45
|
+
</config>
|
46
|
+
XML
|
47
|
+
let(:xml) do
|
48
|
+
REXML::Document.new(doc)
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
allow(Resource::System).to receive(:configuration).and_return(xml)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns the found backup setting' do
|
56
|
+
expect(described_class.find('backup-weekly')).to be_a(described_class)
|
57
|
+
expect(described_class.find('backup-weekly').key).to eq('backup-weekly')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -36,7 +36,7 @@ module Artifactory
|
|
36
36
|
|
37
37
|
context 'when the :client key is not present' do
|
38
38
|
let(:client) { double }
|
39
|
-
before { Artifactory.
|
39
|
+
before { allow(Artifactory).to receive(:client).and_return(client) }
|
40
40
|
|
41
41
|
it 'uses Artifactory.client' do
|
42
42
|
expect(described_class.extract_client!({})).to be(client)
|
@@ -97,7 +97,7 @@ module Artifactory
|
|
97
97
|
|
98
98
|
it 'defaults to the Artifactory.client' do
|
99
99
|
client = double
|
100
|
-
Artifactory.
|
100
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
101
101
|
|
102
102
|
expect(subject.client).to be(client)
|
103
103
|
end
|
@@ -132,7 +132,7 @@ module Artifactory
|
|
132
132
|
|
133
133
|
describe '#inspect' do
|
134
134
|
it 'includes all the attributes' do
|
135
|
-
subject.
|
135
|
+
allow(subject).to receive(:attributes) do
|
136
136
|
{ foo: 'bar' }
|
137
137
|
end
|
138
138
|
|
@@ -5,8 +5,8 @@ module Artifactory
|
|
5
5
|
let(:client) { double(:client) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
Artifactory.
|
9
|
-
client.
|
8
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
9
|
+
allow(client).to receive(:get).and_return(response) if defined?(response)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.all' do
|
@@ -25,7 +25,7 @@ module Artifactory
|
|
25
25
|
|
26
26
|
context 'when the system has no builds' do
|
27
27
|
it 'returns an empty array' do
|
28
|
-
client.
|
28
|
+
allow(client).to receive(:get).and_raise(Error::HTTPError.new('status' => 404))
|
29
29
|
expect(described_class.all).to be_empty
|
30
30
|
end
|
31
31
|
end
|
@@ -5,8 +5,8 @@ module Artifactory
|
|
5
5
|
let(:client) { double(:client) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
Artifactory.
|
9
|
-
client.
|
8
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
9
|
+
allow(client).to receive(:get).and_return(response) if defined?(response)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.all' do
|
@@ -18,9 +18,9 @@ module Artifactory
|
|
18
18
|
]
|
19
19
|
end
|
20
20
|
before do
|
21
|
-
described_class.
|
22
|
-
described_class.
|
23
|
-
described_class.
|
21
|
+
allow(described_class).to receive(:from_url).with('a', client: client).and_return('a')
|
22
|
+
allow(described_class).to receive(:from_url).with('b', client: client).and_return('b')
|
23
|
+
allow(described_class).to receive(:from_url).with('c', client: client).and_return('c')
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'gets /api/security/groups' do
|
@@ -66,7 +66,7 @@ module Artifactory
|
|
66
66
|
instance = described_class.from_hash(hash)
|
67
67
|
expect(instance.name).to eq('readers')
|
68
68
|
expect(instance.description).to eq('This list of read-only users')
|
69
|
-
expect(instance.auto_join).to
|
69
|
+
expect(instance.auto_join).to be_truthy
|
70
70
|
expect(instance.realm).to eq('artifactory')
|
71
71
|
expect(instance.realm_attributes).to be_nil
|
72
72
|
end
|
@@ -5,8 +5,8 @@ module Artifactory
|
|
5
5
|
let(:client) { double(:client) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
Artifactory.
|
9
|
-
client.
|
8
|
+
allow(Artifactory).to receive(:client).and_return(client)
|
9
|
+
allow(client).to receive(:get).and_return(response) if defined?(response)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.all' do
|
@@ -24,7 +24,7 @@ module Artifactory
|
|
24
24
|
end
|
25
25
|
|
26
26
|
before do
|
27
|
-
Resource::System.
|
27
|
+
allow(Resource::System).to receive(:configuration).and_return(xml)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns the layouts' do
|
@@ -49,7 +49,7 @@ module Artifactory
|
|
49
49
|
end
|
50
50
|
|
51
51
|
before do
|
52
|
-
Resource::System.
|
52
|
+
allow(Resource::System).to receive(:configuration).and_return(xml)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'returns the found layout' do
|