-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathapi_authorization_spec.rb
82 lines (61 loc) · 2.47 KB
/
api_authorization_spec.rb
1
2
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require "spec_helper"
describe "Api Authorization" do
before :all do
@mock_api = MockedApi
end
before do
Cloudinary::config.cloud_name = DUMMY_CLOUD
Cloudinary::config.api_key = API_KEY
Cloudinary::config.api_secret = API_SECRET
end
after { Cloudinary::reset_config }
it "tests oauth_token admin api" do
Cloudinary::config.oauth_token = OAUTH_TOKEN
res = @mock_api.ping
expect(res["headers"]["Authorization"]).not_to be_nil
expect(res["headers"]["Authorization"]).to eq("Bearer #{OAUTH_TOKEN}")
end
it "tests oauth token as an option admin api" do
res = @mock_api.ping(:oauth_token => OAUTH_TOKEN)
expect(res["headers"]["Authorization"]).not_to be_nil
expect(res["headers"]["Authorization"]).to eq("Bearer #{OAUTH_TOKEN}")
end
it "tests key and secret admin api" do
res = @mock_api.ping
expect(res["headers"]["Authorization"]).not_to be_nil
expect(res["headers"]["Authorization"]).to eq("Basic a2V5OnNlY3JldA==")
end
it "tests missing credentials admin api" do
Cloudinary::config.oauth_token = nil
Cloudinary::config.api_key = nil
Cloudinary::config.api_secret = nil
expect { Cloudinary::Api.ping }.to raise_error(/Must supply api_key/)
end
it "tests oauth token upload api" do
Cloudinary::config.oauth_token = OAUTH_TOKEN
res = MockedUploader.upload(TEST_IMG)
expect(res["headers"]["Authorization"]).not_to be_nil
expect(res["headers"]["Authorization"]).to eq("Bearer #{OAUTH_TOKEN}")
expect(res["headers"]["signature"]).to be_nil
end
it "tests oauth token as an option upload api" do
res = MockedUploader.upload(TEST_IMG, :oauth_token => OAUTH_TOKEN)
expect(res["headers"]["Authorization"]).not_to be_nil
expect(res["headers"]["Authorization"]).to eq("Bearer #{OAUTH_TOKEN}")
end
it "tests key and secret upload api" do
res = MockedUploader.upload(TEST_IMG)
expect(res["headers"]["Authorization"]).to be_nil
expect(res["payload"]["signature"]).not_to be_nil
expect(res["payload"]["api_key"]).not_to be_nil
end
it "tests missing credentials upload api" do
Cloudinary::config.oauth_token = nil
Cloudinary::config.api_key = nil
Cloudinary::config.api_secret = nil
expect { Cloudinary::Uploader.upload(TEST_IMG) }.to raise_error(/Must supply api_key/)
# no credentials required for unsigned upload
res = MockedUploader.unsigned_upload(TEST_IMG, API_TEST_PRESET)
expect(res["payload"]["upload_preset"]).not_to be_nil
end
end