apple_dep_client 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/error_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Error do
|
4
4
|
describe ".check_request_error" do
|
5
5
|
it "raises an error if the properties match" do
|
6
|
-
response = Typhoeus::Response.new(response_code: 400, body:
|
7
|
-
expect{AppleDEPClient::Error.check_request_error response}.to raise_error AppleDEPClient::Error::RequestError,
|
6
|
+
response = Typhoeus::Response.new(response_code: 400, body: "INVALID_CURSOR")
|
7
|
+
expect { AppleDEPClient::Error.check_request_error response }.to raise_error AppleDEPClient::Error::RequestError, "InvalidCursor"
|
8
8
|
end
|
9
9
|
it "will check that the response code is 200" do
|
10
|
-
response = Typhoeus::Response.new(response_code: 500, body:
|
11
|
-
expect{AppleDEPClient::Error.check_request_error response}.to raise_error AppleDEPClient::Error::RequestError,
|
10
|
+
response = Typhoeus::Response.new(response_code: 500, body: "")
|
11
|
+
expect { AppleDEPClient::Error.check_request_error response }.to raise_error AppleDEPClient::Error::RequestError, "GenericError"
|
12
12
|
end
|
13
13
|
it "can also check for auth errors" do
|
14
|
-
response = Typhoeus::Response.new(response_code: 401, body:
|
15
|
-
expect{AppleDEPClient::Error.check_request_error(response, auth:true)}.to raise_error AppleDEPClient::Error::RequestError,
|
14
|
+
response = Typhoeus::Response.new(response_code: 401, body: "")
|
15
|
+
expect { AppleDEPClient::Error.check_request_error(response, auth: true) }.to raise_error AppleDEPClient::Error::RequestError, "Unauthorized"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
describe ".get_errors" do
|
19
19
|
it "can return normal errors" do
|
20
20
|
errors = AppleDEPClient::Error.get_errors
|
21
|
-
expect(errors.map{|error| error[0]}).to include
|
21
|
+
expect(errors.map { |error| error[0] }).to include "MalformedRequest"
|
22
22
|
end
|
23
23
|
it "can return auth errors" do
|
24
|
-
errors = AppleDEPClient::Error.get_errors auth:true
|
25
|
-
expect(errors.map{|error| error[0]}).to include
|
24
|
+
errors = AppleDEPClient::Error.get_errors auth: true
|
25
|
+
expect(errors.map { |error| error[0] }).to include "BadRequest"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/profile_spec.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Profile do
|
4
4
|
describe ".define" do
|
5
5
|
it "sends a profile to apple" do
|
6
|
-
data = {profile_name:
|
6
|
+
data = { profile_name: "asdf" }
|
7
7
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Profile::DEFINE_PATH)
|
8
8
|
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :post, '{"profile_name":"asdf"}').once
|
9
9
|
AppleDEPClient::Profile.define data
|
10
10
|
end
|
11
11
|
it "doesn't send unrecognized data to apple" do
|
12
|
-
data = {asdf:
|
12
|
+
data = { asdf: "asdf" }
|
13
13
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Profile::DEFINE_PATH)
|
14
|
-
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :post,
|
14
|
+
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :post, "{}").once
|
15
15
|
AppleDEPClient::Profile.define data
|
16
16
|
end
|
17
17
|
end
|
@@ -19,21 +19,21 @@ describe AppleDEPClient::Profile do
|
|
19
19
|
it "sends a request to assign a profile to data" do
|
20
20
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Profile::ASSIGN_PATH)
|
21
21
|
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :put, anything).once
|
22
|
-
AppleDEPClient::Profile.assign(
|
22
|
+
AppleDEPClient::Profile.assign("1", "a")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
describe ".fetch" do
|
26
26
|
it "sends a request to fetch a profile" do
|
27
27
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Profile::FETCH_PATH)
|
28
|
-
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :get, nil, params:anything).once
|
29
|
-
AppleDEPClient::Profile.fetch(
|
28
|
+
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :get, nil, params: anything).once
|
29
|
+
AppleDEPClient::Profile.fetch("1")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
describe ".remove" do
|
33
33
|
it "sends a request to remove profiles from devices" do
|
34
34
|
url = AppleDEPClient::Request.make_url(AppleDEPClient::Profile::REMOVE_PATH)
|
35
35
|
expect(AppleDEPClient::Request).to receive(:make_request).with(url, :delete, anything).once
|
36
|
-
AppleDEPClient::Profile.remove(
|
36
|
+
AppleDEPClient::Profile.remove("a")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/spec/request_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe AppleDEPClient::Request do
|
4
4
|
before(:each) do
|
@@ -7,43 +7,43 @@ describe AppleDEPClient::Request do
|
|
7
7
|
describe ".make_request" do
|
8
8
|
it "can make a request and return the body" do
|
9
9
|
expect(AppleDEPClient::Request).to receive(:make_headers).once
|
10
|
-
response = Typhoeus::Response.new(return_code: :ok, response_code: 200, body:
|
11
|
-
Typhoeus.stub(
|
10
|
+
response = Typhoeus::Response.new(return_code: :ok, response_code: 200, body: "[]")
|
11
|
+
Typhoeus.stub("url").and_return response
|
12
12
|
expect(AppleDEPClient::Error).to receive(:check_request_error).with(response).once
|
13
|
-
body = AppleDEPClient::Request.make_request(
|
13
|
+
body = AppleDEPClient::Request.make_request("url", "get", "asdf")
|
14
14
|
expect(body).to eq []
|
15
15
|
end
|
16
16
|
it "can override default headers" do
|
17
17
|
expect(AppleDEPClient::Request).to_not receive(:make_headers)
|
18
18
|
response = Typhoeus::Response.new(return_code: :ok, response_code: 200, body: '{"qwer": 2}')
|
19
|
-
Typhoeus.stub(
|
19
|
+
Typhoeus.stub("url").and_return response
|
20
20
|
expect(AppleDEPClient::Error).to receive(:check_request_error).with(response).once
|
21
|
-
body = AppleDEPClient::Request.make_request(
|
22
|
-
expect(body).to eq(
|
21
|
+
body = AppleDEPClient::Request.make_request("url", "get", "asdf", headers: {})
|
22
|
+
expect(body).to eq("qwer" => 2)
|
23
23
|
end
|
24
24
|
it "can add params to the url" do
|
25
25
|
expect(AppleDEPClient::Request).to receive(:make_headers)
|
26
26
|
response = Typhoeus::Response.new(return_code: :ok, response_code: 200, body: '{"qwer": 2}')
|
27
|
-
Typhoeus.stub(
|
28
|
-
body = AppleDEPClient::Request.make_request(
|
29
|
-
expect(body).to eq(
|
27
|
+
Typhoeus.stub("url").and_return response
|
28
|
+
body = AppleDEPClient::Request.make_request("url", "get", "asdf", params: { "a" => "b" })
|
29
|
+
expect(body).to eq("qwer" => 2)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
describe ".make_headers" do
|
33
33
|
it "will make a hash of headers" do
|
34
|
-
expect(AppleDEPClient::Auth).to receive(:get_session_token).and_return(
|
34
|
+
expect(AppleDEPClient::Auth).to receive(:get_session_token).and_return("asdf").once
|
35
35
|
headers = AppleDEPClient::Request.make_headers
|
36
|
-
expect(headers[
|
37
|
-
expect(headers[
|
38
|
-
expect(headers[
|
39
|
-
expect(headers[
|
36
|
+
expect(headers["User-Agent"]).to include AppleDEPClient.user_agent
|
37
|
+
expect(headers["X-Server-Protocol-Version"]).to eq "2"
|
38
|
+
expect(headers["X-ADM-Auth-Session"]).to eq "asdf"
|
39
|
+
expect(headers["Content-Type"]).to eq "application/json;charset=UTF8"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe ".make_url" do
|
44
44
|
it "will make a url from the config and a path" do
|
45
|
-
AppleDEPClient.apple_dep_server =
|
46
|
-
expect(AppleDEPClient::Request.make_url(
|
45
|
+
AppleDEPClient.apple_dep_server = "qwer"
|
46
|
+
expect(AppleDEPClient::Request.make_url("asdf")).to eq "qwerasdf"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/token_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "AppleDEPClient::Token" do
|
4
4
|
describe ".decode_token" do
|
@@ -6,32 +6,32 @@ describe "AppleDEPClient::Token" do
|
|
6
6
|
expect(AppleDEPClient::Token).to receive(:parse_data).once
|
7
7
|
expect(AppleDEPClient::Token).to receive(:create_temp_file).twice.and_call_original
|
8
8
|
expect(AppleDEPClient::Token).to receive(:remove_temp_file).twice
|
9
|
-
expect(AppleDEPClient::Token).to receive(:run_command).once.and_return [
|
10
|
-
AppleDEPClient::Token.decode_token(
|
9
|
+
expect(AppleDEPClient::Token).to receive(:run_command).once.and_return ["{}", ""]
|
10
|
+
AppleDEPClient::Token.decode_token("sample data")
|
11
11
|
end
|
12
|
-
it
|
12
|
+
it "will raise an error if the decryption returned no data" do
|
13
13
|
expect(AppleDEPClient::Token).to_not receive(:parse_data)
|
14
14
|
expect(AppleDEPClient::Token).to receive(:create_temp_file).twice.and_call_original
|
15
15
|
expect(AppleDEPClient::Token).to receive(:remove_temp_file).twice
|
16
|
-
expect(AppleDEPClient::Token).to receive(:run_command).once.and_return [
|
17
|
-
expect{AppleDEPClient::Token.decode_token(
|
16
|
+
expect(AppleDEPClient::Token).to receive(:run_command).once.and_return ["", "error"]
|
17
|
+
expect { AppleDEPClient::Token.decode_token("sample data") }.to raise_error AppleDEPClient::Error::TokenError
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe ".create_temp_file" do
|
22
22
|
it "will not write a binary Tempfile by default" do
|
23
23
|
expect_any_instance_of(Tempfile).to_not receive :binmode
|
24
|
-
AppleDEPClient::Token.create_temp_file(
|
24
|
+
AppleDEPClient::Token.create_temp_file("asdf", "qwer")
|
25
25
|
end
|
26
26
|
it "can write a binary Tempfile" do
|
27
27
|
expect_any_instance_of(Tempfile).to receive :binmode
|
28
|
-
AppleDEPClient::Token.create_temp_file(
|
28
|
+
AppleDEPClient::Token.create_temp_file("asdf", "qwer", binary: true)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe ".run_command" do
|
33
33
|
it "can run a command" do
|
34
|
-
command =
|
34
|
+
command = "ls"
|
35
35
|
data, errors = AppleDEPClient::Token.run_command command
|
36
36
|
expect(data).to_not be_empty
|
37
37
|
expect(errors).to be_empty
|
@@ -40,27 +40,27 @@ describe "AppleDEPClient::Token" do
|
|
40
40
|
|
41
41
|
describe ".parse_data" do
|
42
42
|
let(:data) { "-----BEGIN MESSAGE-----\n{\"consumer_key\": \"asdf\"}\n-----END MESSAGE-----" }
|
43
|
-
it
|
44
|
-
expect(AppleDEPClient::Token.parse_data(data)).to eq ({consumer_key:
|
43
|
+
it "can parse JSON data and return it" do
|
44
|
+
expect(AppleDEPClient::Token.parse_data(data)).to eq ({ consumer_key: "asdf" })
|
45
45
|
end
|
46
|
-
it
|
46
|
+
it "will save JSON data" do
|
47
47
|
expect(AppleDEPClient::Token).to receive(:save_data)
|
48
48
|
AppleDEPClient::Token.parse_data(data)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe ".save_data" do
|
53
|
-
let(:data) { {consumer_key:
|
54
|
-
it
|
53
|
+
let(:data) { { consumer_key: "asdf", access_token: "qwer" } }
|
54
|
+
it "can save data" do
|
55
55
|
AppleDEPClient::Token.save_data(data)
|
56
|
-
expect(AppleDEPClient.consumer_key).to eq
|
57
|
-
expect(AppleDEPClient.access_token).to eq
|
56
|
+
expect(AppleDEPClient.consumer_key).to eq "asdf"
|
57
|
+
expect(AppleDEPClient.access_token).to eq "qwer"
|
58
58
|
end
|
59
|
-
it
|
60
|
-
AppleDEPClient.consumer_key = lambda {
|
59
|
+
it "will not overwrite lambdas" do
|
60
|
+
AppleDEPClient.consumer_key = lambda { "lambda" }
|
61
61
|
AppleDEPClient::Token.save_data(data)
|
62
|
-
expect(AppleDEPClient.consumer_key).to eq
|
63
|
-
expect(AppleDEPClient.access_token).to eq
|
62
|
+
expect(AppleDEPClient.consumer_key).to eq "lambda"
|
63
|
+
expect(AppleDEPClient.access_token).to eq "qwer"
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apple_dep_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.7
|
33
|
+
version: '0.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.7
|
40
|
+
version: '0.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: plist
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,8 +118,10 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
121
122
|
- ".simplecov"
|
122
123
|
- CHANGELOG.md
|
124
|
+
- CONTRIBUTING.md
|
123
125
|
- Gemfile
|
124
126
|
- MIT-LICENSE.txt
|
125
127
|
- README.md
|