apireaper 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apireaper.gemspec +1 -1
- data/lib/apireaper/cli.rb +10 -0
- data/lib/apireaper/requester.rb +10 -0
- data/lib/apireaper/version.rb +1 -1
- data/spec/apireaper/requester_spec.rb +15 -0
- data/spec/apireaper/stubs/servers_stubs.rb +10 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d317795b7fe576e817517d7ea79852c354ef181
|
4
|
+
data.tar.gz: 2babd32b5f71578dd0d0be9d92bcab8f94cdf653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d32fb911b4345c8fc93d4ab711e1a044f402b329d44f9dc5edc4d77c624da25852c9e331017a633e241d80e36982a5c6eb861dc64fd603116d3009ceae46f1e
|
7
|
+
data.tar.gz: bf4359abd6d6b62decbaea7cee1260b0b725e560317b178f93eafc838ca83f95e667790d1fb383500b28b2d6af04ed35844d942b06bf216d9d4e70c3120d1469
|
data/apireaper.gemspec
CHANGED
data/lib/apireaper/cli.rb
CHANGED
@@ -34,6 +34,16 @@ module APIReaper
|
|
34
34
|
desc: 'Http headers used with the request (comma separated). ' \
|
35
35
|
'<key>:<value>[,<key>:<value>[,...]]'
|
36
36
|
)
|
37
|
+
option(
|
38
|
+
:user,
|
39
|
+
aliases: ['-u'],
|
40
|
+
desc: 'User name in order to login. See also password option.'
|
41
|
+
)
|
42
|
+
option(
|
43
|
+
:password,
|
44
|
+
aliases: ['-p'],
|
45
|
+
desc: 'User password in order to login. See also user option.'
|
46
|
+
)
|
37
47
|
option(
|
38
48
|
:data,
|
39
49
|
aliases: ['-d'],
|
data/lib/apireaper/requester.rb
CHANGED
@@ -37,6 +37,14 @@ module APIReaper
|
|
37
37
|
exit errno
|
38
38
|
end
|
39
39
|
|
40
|
+
# Set the authentication data
|
41
|
+
def basic_auth(request)
|
42
|
+
unless @opts['user'].nil? || @opts['password'].nil?
|
43
|
+
request.basic_auth(@opts['user'], @opts['password'])
|
44
|
+
end
|
45
|
+
request
|
46
|
+
end
|
47
|
+
|
40
48
|
# Select the right data type
|
41
49
|
def format_data(request)
|
42
50
|
return request if @opts['data'].nil?
|
@@ -86,6 +94,7 @@ module APIReaper
|
|
86
94
|
def rest_request_get
|
87
95
|
req = Net::HTTP::Get.new(@uri.request_uri)
|
88
96
|
req = format_header(req)
|
97
|
+
req = basic_auth(req)
|
89
98
|
@http.request(req)
|
90
99
|
end
|
91
100
|
|
@@ -94,6 +103,7 @@ module APIReaper
|
|
94
103
|
req = Net::HTTP::Post.new(@uri.request_uri)
|
95
104
|
req = format_data(req)
|
96
105
|
req = format_header(req)
|
106
|
+
req = basic_auth(req)
|
97
107
|
@http.request(req)
|
98
108
|
end
|
99
109
|
|
data/lib/apireaper/version.rb
CHANGED
@@ -26,6 +26,9 @@ def print_out(code)
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe APIReaper::Requester do # rubocop:disable Metrics/BlockLength
|
29
|
+
opts_auth = '-u user -p passwd'
|
30
|
+
opts_wauth = '-u wrong -p passwd'
|
31
|
+
|
29
32
|
%w[delete put].each do |method|
|
30
33
|
context "check #{method} http://api.test.yueyehua.net/ -q" do
|
31
34
|
it 'tries unimplemented commands.' do
|
@@ -48,6 +51,18 @@ describe APIReaper::Requester do # rubocop:disable Metrics/BlockLength
|
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
54
|
+
context "check post http://api.user.yueyehua.net/ #{opts_auth}" do
|
55
|
+
it 'tries a user and a password.' do
|
56
|
+
expect { start(self) }.to output(print_out(200)).to_stdout
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "check post http://api.user.yueyehua.net/ #{opts_wauth}" do
|
61
|
+
it 'tries a wrong user and a password.' do
|
62
|
+
expect { start(self) }.to raise_error(SystemExit)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
51
66
|
context 'check post http://api.test.yueyehua.net/ -h k:v' do
|
52
67
|
it 'requests an API with headers.' do
|
53
68
|
expect { start(self) }.to output(print_out(201)).to_stdout
|
@@ -21,13 +21,21 @@ def read_file(file)
|
|
21
21
|
File.read(File.join(dir, '..', '..', 'files', file))
|
22
22
|
end
|
23
23
|
|
24
|
-
RSpec.configure do |config|
|
25
|
-
config.before(:each) do
|
24
|
+
RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
|
25
|
+
config.before(:each) do # rubocop:disable Metrics/BlockLength
|
26
26
|
# requests an API without extra arguments
|
27
27
|
stub_request(:post, 'http://api.test.yueyehua.net/')
|
28
28
|
.to_return('status' => 200, 'body' => '{}', 'headers' => {})
|
29
29
|
stub_request(:get, 'http://api.test.yueyehua.net/')
|
30
30
|
.to_return('status' => 200, 'body' => '{}', 'headers' => {})
|
31
|
+
# request with good credentials
|
32
|
+
stub_request(:post, 'http://api.user.yueyehua.net/')
|
33
|
+
.with(basic_auth: %w[user passwd])
|
34
|
+
.to_return('status' => 200, 'body' => '{}', 'headers' => {})
|
35
|
+
# request with wrong credentials
|
36
|
+
stub_request(:post, 'http://api.user.yueyehua.net/')
|
37
|
+
.with(basic_auth: %w[wrong passwd])
|
38
|
+
.to_return('status' => 401, 'body' => '{}', 'headers' => {})
|
31
39
|
# requests an API with headers
|
32
40
|
stub_request(:post, 'http://api.test.yueyehua.net/')
|
33
41
|
.with('headers' => { 'k' => 'v' })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apireaper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Delaplace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.0.2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.0.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|