apple_dep_client 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +599 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +19 -0
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/apple_dep_client.gemspec +6 -6
- data/example/example.rb +14 -14
- data/lib/apple_dep_client.rb +10 -10
- data/lib/apple_dep_client/account.rb +1 -1
- data/lib/apple_dep_client/auth.rb +12 -12
- data/lib/apple_dep_client/callback.rb +5 -6
- data/lib/apple_dep_client/configuration.rb +5 -5
- data/lib/apple_dep_client/device.rb +13 -13
- data/lib/apple_dep_client/error.rb +27 -29
- data/lib/apple_dep_client/hacks/typhoeus_request.rb +8 -8
- data/lib/apple_dep_client/profile.rb +9 -9
- data/lib/apple_dep_client/request.rb +7 -7
- data/lib/apple_dep_client/token.rb +11 -11
- data/lib/apple_dep_client/version.rb +1 -1
- data/spec/account_spec.rb +3 -3
- data/spec/auth_spec.rb +10 -10
- data/spec/callback_spec.rb +11 -11
- data/spec/configuration_spec.rb +15 -15
- data/spec/device_spec.rb +34 -34
- data/spec/error_spec.rb +10 -10
- data/spec/profile_spec.rb +8 -8
- data/spec/request_spec.rb +17 -17
- data/spec/spec_helper.rb +2 -2
- data/spec/token_spec.rb +20 -20
- data/spec/version_spec.rb +2 -2
- metadata +6 -4
@@ -1,11 +1,11 @@
|
|
1
1
|
# This contains a few hacks that adds support for non-ancient versions of Typhoeus to
|
2
2
|
# the ancient dead ruby oauth gem
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
4
|
+
require "oauth/request_proxy/base"
|
5
|
+
require "typhoeus"
|
6
|
+
require "typhoeus/request"
|
7
|
+
require "uri"
|
8
|
+
require "cgi"
|
9
9
|
|
10
10
|
module OAuth::RequestProxy::Typhoeus
|
11
11
|
class Request < OAuth::RequestProxy::Base
|
@@ -23,7 +23,7 @@ module OAuth::RequestProxy::Typhoeus
|
|
23
23
|
|
24
24
|
def method
|
25
25
|
request_method = request.options[:method].to_s.upcase
|
26
|
-
request_method.empty? ?
|
26
|
+
request_method.empty? ? "GET" : request_method
|
27
27
|
end
|
28
28
|
|
29
29
|
def uri
|
@@ -47,11 +47,11 @@ module OAuth::RequestProxy::Typhoeus
|
|
47
47
|
|
48
48
|
def post_parameters
|
49
49
|
# Post params are only used if posting form data
|
50
|
-
if method ==
|
50
|
+
if method == "POST"
|
51
51
|
OAuth::Helper.stringify_keys(request.params || {})
|
52
52
|
else
|
53
53
|
{}
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Methods for getting and setting device profiles
|
2
2
|
|
3
|
-
require
|
3
|
+
require "json"
|
4
4
|
|
5
5
|
module AppleDEPClient
|
6
6
|
module Profile
|
@@ -10,29 +10,29 @@ module AppleDEPClient
|
|
10
10
|
REMOVE_PATH = "/profile/devices"
|
11
11
|
|
12
12
|
PROFILE_KEYS = [:profile_name, :url, :allow_pairing, :is_supervised,
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
:is_mandatory, :is_mdm_removable, :support_phone_number,
|
14
|
+
:support_email_address, :org_magic, :anchor_certs, :supervising_host_certs,
|
15
|
+
:skip_setup_items, :department, :devices]
|
16
16
|
|
17
17
|
def self.define(profile_data)
|
18
|
-
profile_data.select!{|key,
|
18
|
+
profile_data.select! { |key, _value| PROFILE_KEYS.include? key.to_sym }
|
19
19
|
profile_data = JSON.dump profile_data
|
20
20
|
AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(DEFINE_PATH), :post, profile_data)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.assign(profile_uuid, devices)
|
24
|
-
body = {"profile_uuid" => profile_uuid, "devices" => devices}
|
24
|
+
body = { "profile_uuid" => profile_uuid, "devices" => devices }
|
25
25
|
body = JSON.dump body
|
26
26
|
AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(ASSIGN_PATH), :put, body)
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.fetch(profile_uuid)
|
30
|
-
params = {
|
31
|
-
AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(FETCH_PATH), :get, nil, params:params)
|
30
|
+
params = { "profile_uuid" => profile_uuid }
|
31
|
+
AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(FETCH_PATH), :get, nil, params: params)
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.remove(devices)
|
35
|
-
body = {"devices" => devices}
|
35
|
+
body = { "devices" => devices }
|
36
36
|
body = JSON.dump body
|
37
37
|
AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(REMOVE_PATH), :delete, body)
|
38
38
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# Wrapper around requests to DEP endpoint
|
2
2
|
# Will also handle any error conditions
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "json"
|
5
|
+
require "typhoeus"
|
6
6
|
|
7
7
|
module AppleDEPClient
|
8
8
|
module Request
|
9
9
|
DEFAULT_HEADERS = {
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
"User-Agent" => "#{AppleDEPClient.user_agent}/#{AppleDEPClient::VERSION}",
|
11
|
+
"X-Server-Protocol-Version" => "2",
|
12
|
+
"Content-Type" => "application/json;charset=UTF8",
|
13
13
|
}
|
14
14
|
DEFAULT_HEADERS.freeze
|
15
15
|
|
@@ -31,10 +31,10 @@ module AppleDEPClient
|
|
31
31
|
|
32
32
|
def self.make_headers
|
33
33
|
session_auth_token = AppleDEPClient::Auth.get_session_token
|
34
|
-
DEFAULT_HEADERS.merge(
|
34
|
+
DEFAULT_HEADERS.merge("X-ADM-Auth-Session" => session_auth_token)
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.make_url
|
37
|
+
def self.make_url(path)
|
38
38
|
AppleDEPClient.apple_dep_server + path
|
39
39
|
end
|
40
40
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Methods for processing DEP Server Tokens
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "json"
|
4
|
+
require "open3"
|
5
|
+
require "openssl"
|
6
|
+
require "tempfile"
|
7
7
|
|
8
8
|
module AppleDEPClient
|
9
9
|
module Token
|
@@ -18,13 +18,13 @@ module AppleDEPClient
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.decrypt_data(smime_data)
|
21
|
-
data = create_temp_file(
|
22
|
-
private_key = create_temp_file(
|
21
|
+
data = create_temp_file("data", smime_data)
|
22
|
+
private_key = create_temp_file("key", AppleDEPClient.private_key)
|
23
23
|
command = "openssl smime -decrypt -in #{data.path} -inkey #{private_key.path} -text"
|
24
24
|
decrypted_data, errors = run_command command
|
25
25
|
remove_temp_file data
|
26
26
|
remove_temp_file private_key
|
27
|
-
if decrypted_data ==
|
27
|
+
if decrypted_data == "" || errors != ""
|
28
28
|
raise AppleDEPClient::Error::TokenError, "Incorrect data #{errors}"
|
29
29
|
end
|
30
30
|
decrypted_data
|
@@ -43,20 +43,20 @@ module AppleDEPClient
|
|
43
43
|
file.unlink
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.run_command
|
46
|
+
def self.run_command(command)
|
47
47
|
stdin, stdout, stderr = Open3.popen3 command
|
48
48
|
[stdout.read, stderr.read]
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.parse_data(data)
|
52
52
|
data = strip_wrappers data
|
53
|
-
data = JSON.parse(data,
|
53
|
+
data = JSON.parse(data, symbolize_names: true)
|
54
54
|
save_data data
|
55
55
|
data
|
56
56
|
end
|
57
57
|
|
58
|
-
def self.strip_wrappers
|
59
|
-
data = data.sub(
|
58
|
+
def self.strip_wrappers(data)
|
59
|
+
data = data.sub("-----BEGIN MESSAGE-----", "").sub("-----END MESSAGE-----", "")
|
60
60
|
data.strip
|
61
61
|
end
|
62
62
|
|
data/spec/account_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Account do
|
4
4
|
it "can fetch data" do
|
5
5
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Account::FETCH_PATH)
|
6
|
-
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :get,
|
7
|
-
expect(AppleDEPClient::Account.fetch).to eq
|
6
|
+
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :get, "").and_return("asdf").once
|
7
|
+
expect(AppleDEPClient::Account.fetch).to eq "asdf"
|
8
8
|
end
|
9
9
|
end
|
data/spec/auth_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Auth do
|
4
4
|
before(:each) do
|
@@ -6,10 +6,10 @@ describe AppleDEPClient::Auth do
|
|
6
6
|
end
|
7
7
|
before(:all) do
|
8
8
|
AppleDEPClient.configure do |x|
|
9
|
-
x.consumer_key =
|
10
|
-
x.consumer_secret =
|
11
|
-
x.access_token =
|
12
|
-
x.access_secret =
|
9
|
+
x.consumer_key = "consumer_key"
|
10
|
+
x.consumer_secret = "consumer_secret"
|
11
|
+
x.access_token = "access_token"
|
12
|
+
x.access_secret = "access_secret"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
describe ".get_session_token" do
|
@@ -17,17 +17,17 @@ describe AppleDEPClient::Auth do
|
|
17
17
|
expect(AppleDEPClient::Auth).to receive(:oauth_header).once.and_call_original
|
18
18
|
expect_any_instance_of(Typhoeus::Request).to receive(:run)
|
19
19
|
response = Typhoeus::Response.new(return_code: :ok, response_code: 200)
|
20
|
-
Typhoeus.stub(
|
20
|
+
Typhoeus.stub("/apple/")
|
21
21
|
expect_any_instance_of(Typhoeus::Request).to receive(:response).and_return(response)
|
22
|
-
expect(AppleDEPClient::Error).to receive(:check_request_error).with(response, auth:true)
|
23
|
-
expect(AppleDEPClient::Auth).to receive(:parse_response).with(response).and_return(
|
24
|
-
expect(AppleDEPClient::Auth.get_session_token).to eq
|
22
|
+
expect(AppleDEPClient::Error).to receive(:check_request_error).with(response, auth: true)
|
23
|
+
expect(AppleDEPClient::Auth).to receive(:parse_response).with(response).and_return("asdf").once
|
24
|
+
expect(AppleDEPClient::Auth.get_session_token).to eq "asdf"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
describe ".parse_response" do
|
28
28
|
let(:response) { Typhoeus::Response.new(return_code: :ok, response_code: 200, body: "{\"auth_session_token\":\"1234\"}") }
|
29
29
|
it "will parse out the auth_session_token" do
|
30
|
-
expect(AppleDEPClient::Auth.parse_response response).to eq
|
30
|
+
expect(AppleDEPClient::Auth.parse_response response).to eq "1234"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/spec/callback_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Callback do
|
4
4
|
describe ".decode_callback" do
|
5
5
|
it "will call decrypt_data and feed data to parse_data" do
|
6
|
-
expect(AppleDEPClient::Callback).to receive(:decrypt_data).with(
|
7
|
-
expect(AppleDEPClient::Callback).to receive(:parse_data).with(
|
8
|
-
AppleDEPClient::Callback.decode_callback
|
6
|
+
expect(AppleDEPClient::Callback).to receive(:decrypt_data).with("qwer").and_return("asdf").once
|
7
|
+
expect(AppleDEPClient::Callback).to receive(:parse_data).with("asdf").and_return("zxcv").once
|
8
|
+
AppleDEPClient::Callback.decode_callback "qwer"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe ".decrypt_data" do
|
13
13
|
it "will decrypt data and remove encryption data" do
|
14
|
-
expect(AppleDEPClient::Token).to receive(:create_temp_file).with(
|
15
|
-
expect(AppleDEPClient::Token).to receive(:run_command).and_return([
|
16
|
-
expect(AppleDEPClient::Callback).to receive(:remove_encryption_data).with(
|
17
|
-
AppleDEPClient::Callback.decrypt_data
|
14
|
+
expect(AppleDEPClient::Token).to receive(:create_temp_file).with("data", "asdf", binary: true).and_call_original
|
15
|
+
expect(AppleDEPClient::Token).to receive(:run_command).and_return(["data", ""]).once
|
16
|
+
expect(AppleDEPClient::Callback).to receive(:remove_encryption_data).with("data").once
|
17
|
+
AppleDEPClient::Callback.decrypt_data "asdf"
|
18
18
|
end
|
19
19
|
it "will raise an error if the data cannot be decrypted" do
|
20
|
-
expect(AppleDEPClient::Token).to receive(:create_temp_file).with(
|
21
|
-
expect(AppleDEPClient::Token).to receive(:run_command).and_return([
|
20
|
+
expect(AppleDEPClient::Token).to receive(:create_temp_file).with("data", "asdf", binary: true).and_call_original
|
21
|
+
expect(AppleDEPClient::Token).to receive(:run_command).and_return(["", "error"]).once
|
22
22
|
expect(AppleDEPClient::Callback).to_not receive(:remove_encryption_data)
|
23
|
-
expect{AppleDEPClient::Callback.decrypt_data
|
23
|
+
expect { AppleDEPClient::Callback.decrypt_data "asdf" }.to raise_error AppleDEPClient::Error::CallbackError
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "AppleDEPClient::Configuration" do
|
4
4
|
it "has a default apple_dep_server value" do
|
@@ -6,49 +6,49 @@ describe "AppleDEPClient::Configuration" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "can be configured" do
|
9
|
-
AppleDEPClient.private_key =
|
10
|
-
AppleDEPClient.consumer_key =
|
11
|
-
expect(AppleDEPClient.private_key).to eq
|
12
|
-
expect(AppleDEPClient.consumer_key).to eq
|
9
|
+
AppleDEPClient.private_key = "asdf"
|
10
|
+
AppleDEPClient.consumer_key = "qwer"
|
11
|
+
expect(AppleDEPClient.private_key).to eq "asdf"
|
12
|
+
expect(AppleDEPClient.consumer_key).to eq "qwer"
|
13
13
|
end
|
14
14
|
|
15
15
|
describe ".method_missing" do
|
16
16
|
it "can get value for valid configuration keys" do
|
17
|
-
expect(AppleDEPClient).to receive(:get_value).with(:access_token).and_return
|
18
|
-
expect(AppleDEPClient.access_token).to eq
|
17
|
+
expect(AppleDEPClient).to receive(:get_value).with(:access_token).and_return "asdf"
|
18
|
+
expect(AppleDEPClient.access_token).to eq "asdf"
|
19
19
|
end
|
20
20
|
it "can raise NoMethodError for invalid configuration keys" do
|
21
|
-
expect{AppleDEPClient.asdf}.to raise_error NoMethodError
|
21
|
+
expect { AppleDEPClient.asdf }.to raise_error NoMethodError
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe ".get_value" do
|
26
26
|
it "can get a configuration value directly from the saved value" do
|
27
|
-
AppleDEPClient.private_key =
|
28
|
-
expect(AppleDEPClient.private_key).to eq
|
27
|
+
AppleDEPClient.private_key = "qwer"
|
28
|
+
expect(AppleDEPClient.private_key).to eq "qwer"
|
29
29
|
end
|
30
30
|
it "will get the default value if the instance variable isn't set" do
|
31
31
|
expect(AppleDEPClient.apple_dep_server).to_not be_nil
|
32
32
|
end
|
33
33
|
it "can get a configuration value by calling a Proc" do
|
34
|
-
AppleDEPClient.private_key = lambda { return
|
35
|
-
expect(AppleDEPClient.private_key).to eq
|
34
|
+
AppleDEPClient.private_key = lambda { return "qwer" }
|
35
|
+
expect(AppleDEPClient.private_key).to eq "qwer"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe ".get_default_value" do
|
40
40
|
it "will read the default value from DEP_CONFIG" do
|
41
41
|
apple_dep_server = AppleDEPClient::Configuration::DEP_CONFIG[:apple_dep_server]
|
42
|
-
expect(AppleDEPClient.get_default_value(
|
42
|
+
expect(AppleDEPClient.get_default_value("apple_dep_server")).to eq apple_dep_server
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe ".configure" do
|
47
47
|
it "can be configured in a block" do
|
48
48
|
AppleDEPClient.configure do |x|
|
49
|
-
x.private_key =
|
49
|
+
x.private_key = "asdf"
|
50
50
|
end
|
51
|
-
expect(AppleDEPClient.private_key).to eq
|
51
|
+
expect(AppleDEPClient.private_key).to eq "asdf"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/spec/device_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Device do
|
4
4
|
describe ".fetch" do
|
@@ -6,47 +6,47 @@ describe AppleDEPClient::Device do
|
|
6
6
|
@url = AppleDEPClient::Device::FETCH_PATH
|
7
7
|
end
|
8
8
|
it "will iterate through data to yield devices" do
|
9
|
-
response = {
|
9
|
+
response = { "cursor" => "asdf", "devices" => ["qwer", "zxcv"], "more_to_follow" => "false" }
|
10
10
|
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(nil, @url).and_return(response).once
|
11
11
|
devices = []
|
12
|
-
AppleDEPClient::Device.fetch{|x| devices << x }
|
13
|
-
expect(devices).to eq [
|
12
|
+
AppleDEPClient::Device.fetch { |x| devices << x }
|
13
|
+
expect(devices).to eq ["qwer", "zxcv"]
|
14
14
|
end
|
15
15
|
it "will iterate through multiple responses" do
|
16
|
-
response = {
|
16
|
+
response = { "cursor" => "1", "devices" => ["qwer"], "more_to_follow" => "true" }
|
17
17
|
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(nil, @url).and_return(response).once
|
18
|
-
response = {
|
19
|
-
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(
|
18
|
+
response = { "cursor" => "2", "devices" => ["zxcv"], "more_to_follow" => "false" }
|
19
|
+
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with("1", @url).and_return(response).once
|
20
20
|
devices = []
|
21
|
-
AppleDEPClient::Device.fetch{|x| devices << x }
|
22
|
-
expect(devices).to eq [
|
21
|
+
AppleDEPClient::Device.fetch { |x| devices << x }
|
22
|
+
expect(devices).to eq ["qwer", "zxcv"]
|
23
23
|
end
|
24
24
|
it "will return the last cursor" do
|
25
|
-
response = {
|
25
|
+
response = { "cursor" => "1", "devices" => ["qwer"], "more_to_follow" => "true" }
|
26
26
|
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(nil, @url).and_return(response).once
|
27
|
-
response = {
|
28
|
-
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(
|
29
|
-
cursor = AppleDEPClient::Device.fetch{}
|
30
|
-
expect(cursor).to eq
|
27
|
+
response = { "cursor" => "2", "devices" => ["zxcv"], "more_to_follow" => "false" }
|
28
|
+
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with("1", @url).and_return(response).once
|
29
|
+
cursor = AppleDEPClient::Device.fetch {}
|
30
|
+
expect(cursor).to eq "2"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe ".make_fetch_request" do
|
35
35
|
it "will make a request" do
|
36
|
-
expect(AppleDEPClient::Device).to receive(:fetch_body).with(
|
36
|
+
expect(AppleDEPClient::Device).to receive(:fetch_body).with("cursor").and_return "body"
|
37
37
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Device::FETCH_PATH)
|
38
|
-
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :post,
|
39
|
-
expect(AppleDEPClient::Device.make_fetch_request
|
38
|
+
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :post, "body").and_return("response").once
|
39
|
+
expect(AppleDEPClient::Device.make_fetch_request "cursor", AppleDEPClient::Device::FETCH_PATH).to eq "response"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe ".fetch_body" do
|
44
44
|
it "will create a body to send" do
|
45
|
-
body = {
|
46
|
-
expect(JSON.parse(AppleDEPClient::Device.fetch_body
|
45
|
+
body = { "limit" => AppleDEPClient::Device::FETCH_LIMIT, "cursor" => "asdf" }
|
46
|
+
expect(JSON.parse(AppleDEPClient::Device.fetch_body "asdf")).to eq body
|
47
47
|
end
|
48
48
|
it "won't sent a cursor if it's not specified" do
|
49
|
-
body = {
|
49
|
+
body = { "limit" => AppleDEPClient::Device::FETCH_LIMIT }
|
50
50
|
expect(JSON.parse(AppleDEPClient::Device.fetch_body nil)).to eq body
|
51
51
|
end
|
52
52
|
end
|
@@ -56,35 +56,35 @@ describe AppleDEPClient::Device do
|
|
56
56
|
@url = AppleDEPClient::Device::SYNC_PATH
|
57
57
|
end
|
58
58
|
it "will use a cursor and return results" do
|
59
|
-
response = {
|
60
|
-
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(
|
59
|
+
response = { "cursor" => "2", "devices" => ["zxcv"], "more_to_follow" => "false" }
|
60
|
+
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with("1", @url).and_return(response).once
|
61
61
|
devices = []
|
62
|
-
AppleDEPClient::Device.sync(
|
63
|
-
expect(devices).to eq [
|
62
|
+
AppleDEPClient::Device.sync("1") { |x| devices << x }
|
63
|
+
expect(devices).to eq ["zxcv"]
|
64
64
|
end
|
65
65
|
it "will return a new cursor" do
|
66
|
-
response = {
|
67
|
-
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with(
|
68
|
-
cursor = AppleDEPClient::Device.sync(
|
69
|
-
expect(cursor).to eq
|
66
|
+
response = { "cursor" => "2", "devices" => ["zxcv"], "more_to_follow" => "false" }
|
67
|
+
expect(AppleDEPClient::Device).to receive(:make_fetch_request).with("1", @url).and_return(response).once
|
68
|
+
cursor = AppleDEPClient::Device.sync("1") {}
|
69
|
+
expect(cursor).to eq "2"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe ".details" do
|
74
74
|
it "will return details of devices" do
|
75
|
-
devices = [
|
76
|
-
expect(AppleDEPClient::Request).to receive(:make_request).and_return(
|
75
|
+
devices = ["asdf"]
|
76
|
+
expect(AppleDEPClient::Request).to receive(:make_request).and_return("devices" => { "asdf" => "data" })
|
77
77
|
devices = AppleDEPClient::Device.details devices
|
78
|
-
expect(devices).to eq(
|
78
|
+
expect(devices).to eq("asdf" => "data")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe ".disown" do
|
83
83
|
it "will make a request to disown devices" do
|
84
|
-
devices = [
|
85
|
-
expect(AppleDEPClient::Request).to receive(:make_request).and_return(
|
84
|
+
devices = ["asdf"]
|
85
|
+
expect(AppleDEPClient::Request).to receive(:make_request).and_return("devices" => { "asdf" => "SUCCESS" })
|
86
86
|
devices = AppleDEPClient::Device.disown devices
|
87
|
-
expect(devices).to eq(
|
87
|
+
expect(devices).to eq("asdf" => "SUCCESS")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|