samanage 1.9.33 → 2.0.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +24 -26
- data/changelog.md +13 -0
- data/lib/samanage.rb +2 -1
- data/lib/samanage/api.rb +140 -144
- data/lib/samanage/api/attachments.rb +21 -0
- data/lib/samanage/api/category.rb +24 -19
- data/lib/samanage/api/changes.rb +59 -0
- data/lib/samanage/api/comments.rb +13 -13
- data/lib/samanage/api/contracts.rb +51 -47
- data/lib/samanage/api/custom_fields.rb +23 -19
- data/lib/samanage/api/custom_forms.rb +42 -38
- data/lib/samanage/api/departments.rb +25 -22
- data/lib/samanage/api/groups.rb +43 -39
- data/lib/samanage/api/hardwares.rb +57 -53
- data/lib/samanage/api/incidents.rb +60 -51
- data/lib/samanage/api/mobiles.rb +50 -46
- data/lib/samanage/api/other_assets.rb +47 -43
- data/lib/samanage/api/requester.rb +7 -7
- data/lib/samanage/api/sites.rb +27 -23
- data/lib/samanage/api/users.rb +58 -54
- data/lib/samanage/api/utils.rb +0 -19
- data/lib/samanage/error.rb +20 -20
- data/lib/samanage/url_builder.rb +53 -53
- data/lib/samanage/version.rb +2 -2
- data/samanage.gemspec +2 -2
- data/sample_file.txt +1 -0
- data/spec/api/samanage_attachment_spec.rb +14 -0
- data/spec/api/samanage_category_spec.rb +24 -24
- data/spec/api/samanage_change_spec.rb +98 -0
- data/spec/api/samanage_comments_spec.rb +25 -32
- data/spec/api/samanage_contract_spec.rb +62 -68
- data/spec/api/samanage_custom_field_spec.rb +12 -12
- data/spec/api/samanage_custom_form_spec.rb +24 -24
- data/spec/api/samanage_department_spec.rb +35 -36
- data/spec/api/samanage_group_spec.rb +59 -59
- data/spec/api/samanage_hardware_spec.rb +80 -85
- data/spec/api/samanage_incident_spec.rb +99 -103
- data/spec/api/samanage_mobile_spec.rb +70 -74
- data/spec/api/samanage_other_asset_spec.rb +72 -76
- data/spec/api/samanage_site_spec.rb +45 -45
- data/spec/api/samanage_user_spec.rb +117 -100
- data/spec/api/samanage_util_spec.rb +4 -9
- data/spec/samanage_api_spec.rb +48 -48
- data/spec/samanage_category_spec.rb +21 -28
- data/spec/samanage_url_builder_spec.rb +15 -15
- metadata +15 -11
- data/lib/data/gd-class2-root.crt +0 -24
@@ -1,67 +1,67 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
describe Samanage::Api do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
3
|
+
context 'group' do
|
4
|
+
before(:all) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
7
|
+
@groups = @samanage.groups
|
8
|
+
@users = @samanage.get_users[:data]
|
9
|
+
end
|
10
|
+
it 'get_users: it returns API call of users' do
|
11
|
+
api_call = @samanage.get_groups
|
12
|
+
expect(api_call).to be_a(Hash)
|
13
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
14
|
+
expect(api_call).to have_key(:response)
|
15
|
+
expect(api_call).to have_key(:code)
|
16
|
+
end
|
17
|
+
it 'collects all groups' do
|
18
|
+
group_count = @samanage.get_groups[:total_count]
|
19
|
+
expect(@groups).to be_an(Array)
|
20
|
+
expect(@groups.size).to eq(group_count)
|
21
|
+
end
|
22
|
+
it 'find_group: returns a group card by known id' do
|
23
|
+
sample_id = @groups.sample['id']
|
24
|
+
group = @samanage.find_group(id: sample_id)
|
25
|
+
expect(group[:data]['id']).to eq(sample_id) # id should match found group
|
26
|
+
expect(group[:data]).to have_key('name')
|
27
|
+
end
|
28
|
+
it 'creates a group' do
|
29
|
+
group_name = "Group Name #{(rand*10**4).ceil}"
|
30
|
+
group_description = "Description #{(rand*10**4).ceil}"
|
31
|
+
payload = {
|
32
|
+
group: {
|
33
|
+
name: group_name,
|
34
|
+
description: group_description
|
35
|
+
}
|
36
|
+
}
|
37
|
+
group_create = @samanage.create_group(payload: payload)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
expect(group_create[:data]['id']).to be_an(Integer)
|
40
|
+
expect(group_create[:data]['name']).to eq(group_name)
|
41
|
+
expect(group_create[:code]).to eq(200).or(201)
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
it 'finds a group by name' do
|
45
|
+
group = @groups.sample
|
46
|
+
group_name = group['name']
|
47
|
+
group_id = group['id']
|
48
|
+
found_group_id = @samanage.find_group_id_by_name(group: group_name)
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
expect(group_id).to eq(found_group_id)
|
51
|
+
end
|
52
|
+
it 'returns nil for finding invalid group by name' do
|
53
|
+
group_name = "Invalid-#{rand(100)*100}"
|
54
|
+
found_group_id = @samanage.find_group_id_by_name(group: group_name)
|
55
|
+
expect(found_group_id).to be(nil)
|
56
|
+
end
|
57
|
+
it 'adds member to group' do
|
58
|
+
random_group_id = @groups.sample['id']
|
59
|
+
random_user_email = @users.sample['email']
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
add_user_to_group = @samanage.add_member_to_group(email: random_user_email, group_id: random_group_id)
|
62
|
+
expect(add_user_to_group[:code]).to eq(200).or(201)
|
63
|
+
end
|
64
|
+
it 'deletes a valid group' do
|
65
65
|
sample_group_id = @groups.sample['id']
|
66
66
|
group_delete = @samanage.delete_group(id: sample_group_id)
|
67
67
|
expect(group_delete[:code]).to eq(200).or(201)
|
@@ -70,5 +70,5 @@ describe Samanage::Api do
|
|
70
70
|
invalid_group_id = 0
|
71
71
|
expect{@samanage.delete_group(id: invalid_group_id)}.to raise_error(Samanage::NotFound)
|
72
72
|
end
|
73
|
-
|
73
|
+
end
|
74
74
|
end
|
@@ -1,95 +1,90 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
describe Samanage::Api do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
3
|
+
context 'Hardware' do
|
4
|
+
describe 'API Functions' do
|
5
|
+
before(:all) do
|
6
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
+
@hardwares = @samanage.get_hardwares[:data]
|
9
|
+
end
|
10
|
+
it 'get_hardwares: it returns API call of hardwares' do
|
11
|
+
api_call = @samanage.get_hardwares
|
12
|
+
expect(api_call).to be_a(Hash)
|
13
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
14
|
+
expect(api_call).to have_key(:response)
|
15
|
+
expect(api_call).to have_key(:code)
|
16
|
+
end
|
17
|
+
it 'collect_hardwares: collects array of hardwares' do
|
18
|
+
hardware_count = @samanage.get_hardwares[:total_count]
|
19
|
+
@hardwares = @samanage.hardwares
|
20
|
+
expect(@hardwares).to be_an(Array)
|
21
|
+
expect(@hardwares.size).to eq(hardware_count)
|
22
|
+
end
|
23
|
+
it 'create_hardware(payload: payload): creates a hardware' do
|
24
|
+
hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
25
|
+
serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
26
|
+
payload = {
|
27
|
+
:hardware => {
|
28
|
+
:name => hardware_name,
|
29
|
+
:bio => {:ssn => serial_number},
|
30
|
+
}
|
31
|
+
}
|
32
|
+
hardware_create = @samanage.create_hardware(payload: payload)
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
expect(hardware_create[:data]['id']).to be_an(Integer)
|
35
|
+
expect(hardware_create[:data]['name']).to eq(hardware_name)
|
36
|
+
expect(hardware_create[:code]).to eq(201).or(200)
|
37
|
+
end
|
38
|
+
it 'create_hardware: fails if no serial' do
|
39
|
+
hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
40
|
+
payload = {
|
41
|
+
:hardware => {
|
42
|
+
:name => hardware_name,
|
43
|
+
}
|
44
|
+
}
|
45
|
+
expect{@samanage.create_hardware(payload: payload)}.to raise_error(Samanage::InvalidRequest)
|
46
|
+
end
|
47
|
+
it 'find_hardware: returns a hardware card by known id' do
|
48
|
+
sample_id = @hardwares.sample['id']
|
49
|
+
hardware = @samanage.find_hardware(id: sample_id)
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
expect(hardware[:data]['id']).to eq(sample_id) # id should match found hardware
|
52
|
+
expect(hardware[:data]).to have_key('name')
|
53
|
+
expect(hardware[:data]).to have_key('serial_number')
|
54
|
+
expect(hardware[:data]).to have_key('id')
|
55
|
+
end
|
56
|
+
it 'find_hardware: returns nothing for an invalid id' do
|
57
|
+
sample_id = (0..10).entries.sample
|
58
|
+
expect{@samanage.find_hardware(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found hardware
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
it 'deletes a valid hardware' do
|
61
|
+
it 'finds_hardwares_by_serial' do
|
62
|
+
sample_hardware = @hardwares.sample
|
63
|
+
sample_serial_number = sample_hardware['serial_number']
|
64
|
+
found_assets = @samanage.find_hardwares_by_serial(serial_number: sample_serial_number)
|
65
|
+
found_sample = found_assets[:data].sample
|
66
|
+
expect(sample_serial_number).not_to be(nil)
|
67
|
+
expect(found_sample['serial_number']).not_to be(nil)
|
68
|
+
expect(found_sample['serial_number']).to eq(sample_serial_number)
|
69
|
+
# expect(sample_id).to eq(found_assets[:data].first.dig('id'))
|
70
|
+
end
|
71
|
+
it 'update_hardware: update_hardware by id' do
|
72
|
+
sample_id = @hardwares.sample['id']
|
73
|
+
new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
74
|
+
payload = {
|
75
|
+
:hardware => {
|
76
|
+
:name => new_name
|
77
|
+
}
|
78
|
+
}
|
79
|
+
hardware_update = @samanage.update_hardware(payload: payload, id: sample_id)
|
80
|
+
expect(hardware_update[:data]["name"]).to eq(new_name)
|
81
|
+
expect(hardware_update[:code]).to eq(200).or(201)
|
82
|
+
end
|
83
|
+
it 'deletes a valid hardware' do
|
85
84
|
sample_hardware_id = @hardwares.sample['id']
|
86
85
|
hardware_delete = @samanage.delete_hardware(id: sample_hardware_id)
|
87
86
|
expect(hardware_delete[:code]).to eq(200).or(201)
|
88
87
|
end
|
89
|
-
|
90
|
-
|
91
|
-
# expect{@samanage.delete_hardware(id: invalid_hardware_id)}.to raise_error(Samanage::NotFound)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
88
|
+
end
|
89
|
+
end
|
95
90
|
end
|
@@ -1,113 +1,109 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
describe Samanage::Api do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
3
|
+
context 'Incidents' do
|
4
|
+
describe 'API Functions' do
|
5
|
+
before(:all) do
|
6
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
+
@incidents = @samanage.incidents
|
9
|
+
@users = @samanage.users
|
10
|
+
@incidents_with_archives = @samanage.incidents(options: {audit_archives: true})
|
11
|
+
end
|
12
|
+
it 'get_incidents: it returns API call of incidents' do
|
13
|
+
api_call = @samanage.get_incidents
|
14
|
+
expect(api_call).to be_a(Hash)
|
15
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
16
|
+
expect(api_call).to have_key(:response)
|
17
|
+
expect(api_call).to have_key(:code)
|
18
|
+
end
|
19
|
+
it 'collect_incidents: collects array of incidents' do
|
20
|
+
incident_count = @samanage.get_incidents[:total_count]
|
21
|
+
@incidents = @samanage.incidents
|
22
|
+
expect(@incidents).to be_an(Array)
|
23
|
+
expect(@incidents.size).to eq(incident_count)
|
24
|
+
end
|
25
|
+
it 'create_incident(payload: json): creates a incident' do
|
26
|
+
users_email = @samanage.collect_users.sample['email']
|
27
|
+
incident_name = "Samanage Ruby Incident"
|
28
|
+
json = {
|
29
|
+
:incident => {
|
30
|
+
:requester => {:email => users_email},
|
31
|
+
:name => incident_name,
|
32
|
+
:description => "Description"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
incident_create = @samanage.create_incident(payload: json)
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
expect(incident_create[:data]['id']).to be_an(Integer)
|
38
|
+
expect(incident_create[:data]['name']).to eq(incident_name)
|
39
|
+
expect(incident_create[:code]).to eq(200).or(201)
|
40
|
+
end
|
41
|
+
it 'create_incident: fails if no name/title' do
|
42
|
+
users_email = @users.sample['email']
|
43
|
+
json = {
|
44
|
+
:incident => {
|
45
|
+
:requester => {:email => users_email},
|
46
|
+
:description => "Description"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
expect{@samanage.create_incident(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
50
|
+
end
|
51
|
+
it 'find_incident: returns a incident card by known id' do
|
52
|
+
sample_id = @incidents.sample['id']
|
53
|
+
incident = @samanage.find_incident(id: sample_id)
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
expect(incident[:data]['id']).to eq(sample_id) # id should match found incident
|
56
|
+
expect(incident[:data]).to have_key('name')
|
57
|
+
expect(incident[:data]).to have_key('requester')
|
58
|
+
expect(incident[:data]).to have_key('id')
|
59
|
+
end
|
60
|
+
it 'find_incident: returns more keys with layout=long' do
|
61
|
+
sample_id = @incidents.sample['id']
|
62
|
+
layout_regular_incident = @samanage.find_incident(id: sample_id)
|
63
|
+
layout_long_incident = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
65
|
+
expect(layout_long_incident[:data]['id']).to eq(sample_id) # id should match found incident
|
66
|
+
expect(layout_long_incident[:data].keys.size).to be > (layout_regular_incident.keys.size)
|
67
|
+
expect(layout_long_incident[:data].keys - layout_regular_incident[:data].keys).to_not be([])
|
68
|
+
end
|
69
|
+
it 'find_incident: returns nothing for an invalid id' do
|
70
|
+
sample_id = (0..10).entries.sample
|
71
|
+
expect{@samanage.find_incident(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found incident
|
72
|
+
end
|
73
|
+
it 'update_incident: update_incident by id' do
|
74
|
+
sample_incident = @incidents.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
|
75
|
+
sample_id = sample_incident['id']
|
76
|
+
description = (0...500).map { ('a'..'z').to_a[rand(26)] }.join
|
77
|
+
incident_json = {
|
78
|
+
:incident => {
|
79
|
+
:description => description
|
80
|
+
}
|
81
|
+
}
|
82
|
+
incident_update = @samanage.update_incident(payload: incident_json, id: sample_id)
|
83
|
+
expect(incident_update[:data]['description']).to eq(description)
|
84
|
+
expect(incident_update[:code]).to eq(200).or(201)
|
85
|
+
end
|
86
|
+
it 'finds more data for option[:layout] = "long"' do
|
87
|
+
full_layout_incident_keys = @samanage.incidents(options: {layout: 'long'}).first.keys
|
88
|
+
basic_incident_keys = @samanage.incidents.sample.keys
|
89
|
+
expect(basic_incident_keys.size).to be < full_layout_incident_keys.size
|
90
|
+
end
|
91
|
+
it 'finds more audit archives for option[:audit_archives] = true' do
|
92
|
+
incident_keys = @incidents_with_archives.sample.keys
|
93
|
+
expect(incident_keys).to include
|
94
|
+
('audits')
|
95
|
+
end
|
96
|
+
it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
|
97
|
+
full_incident_keys = @incidents_with_archives.sample.keys
|
98
|
+
basic_incident_keys = @incidents.sample.keys
|
99
|
+
expect(basic_incident_keys.size).to be < full_incident_keys.size
|
100
|
+
expect(full_incident_keys).to include('audits')
|
101
|
+
end
|
102
|
+
it 'deletes a valid incident' do
|
103
103
|
sample_incident_id = @incidents.sample['id']
|
104
104
|
incident_delete = @samanage.delete_incident(id: sample_incident_id)
|
105
105
|
expect(incident_delete[:code]).to eq(200).or(201)
|
106
106
|
end
|
107
|
-
|
108
|
-
|
109
|
-
# expect{@samanage.delete_incident(id: invalid_incident_id)}.to raise_error(Samanage::NotFound)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
107
|
+
end
|
108
|
+
end
|
113
109
|
end
|