inspect_request 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +31 -5
- data/lib/inspect_request.rb +49 -39
- data/lib/inspect_request/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc1422da3ee98462f05f5029b842c1dbab17ee2
|
4
|
+
data.tar.gz: bb43c9e4091551bbd89a140ca5abd8c209b638b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a00de31c9c6620a8672c4573b2a343d8645aaf8fd2bc538d65d1a78bddf96744065a587b74770b8d6d3cf4764bcfbc2b62abfcb677eb39891de9ad75e5980272
|
7
|
+
data.tar.gz: 6dc0f17ff6d1c3bae9a623c398e341afcdf800df19cab2350366d7c07b65bf4edaa9dfff75561a4d953800b146c74736c12683b3849fb836eb96907b320eb574
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ This library will provide you with a proxy (Ritm) which make it possible to insp
|
|
4
4
|
It similar to what mockserver provide, but much simpler (less feature as well).
|
5
5
|
Under the verification function, you have a copy of the request. And you can inspect it however you want. In the end, you just need to return true/false.
|
6
6
|
|
7
|
-
Default port is 7777. You cannot change it yet.
|
8
|
-
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
Add this line to your application's Gemfile:
|
@@ -32,7 +30,7 @@ foo = InspectRequest::Checker.new
|
|
32
30
|
|
33
31
|
# we can configure our proxy details similar to Ritm
|
34
32
|
foo.configure do
|
35
|
-
proxy[:bind_port] =
|
33
|
+
proxy[:bind_port] = 8080 # default port
|
36
34
|
end
|
37
35
|
|
38
36
|
foo.verify do |req|
|
@@ -40,7 +38,7 @@ foo.verify do |req|
|
|
40
38
|
end
|
41
39
|
|
42
40
|
# make sure to go throuh our proxy
|
43
|
-
RestClient.proxy = 'http://127.0.0.1:
|
41
|
+
RestClient.proxy = 'http://127.0.0.1:8080'
|
44
42
|
# send a test request
|
45
43
|
RestClient.get 'http://example.org'
|
46
44
|
|
@@ -48,6 +46,34 @@ sleep 1
|
|
48
46
|
foo.fulfilled? # true
|
49
47
|
```
|
50
48
|
|
49
|
+
## Self-signed Certificate
|
50
|
+
Use the following command to generate `insecure_ca.pem` and `insecure_ca.key`
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require 'ritm/certs/ca'
|
54
|
+
|
55
|
+
ca = Ritm::CA.create common_name: 'Inspect Request'
|
56
|
+
|
57
|
+
File.write('insecure_ca.pem', ca.pem)
|
58
|
+
File.write('insecure_ca.key', ca.private_key.to_s)
|
59
|
+
```
|
60
|
+
|
61
|
+
Then we'll need to use it like this:
|
62
|
+
```
|
63
|
+
INSECURE_CA_PEM = './insecure_ca.pem'.freeze
|
64
|
+
INSECURE_CA_KEY = './insecure_ca.key'.freeze
|
65
|
+
|
66
|
+
foo = InspectRequest::Checker.new
|
67
|
+
foo.configure do
|
68
|
+
ssl_reverse_proxy.ca[:pem] = INSECURE_CA_PEM
|
69
|
+
ssl_reverse_proxy.ca[:key] = INSECURE_CA_KEY
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
Finally, you can test it using curl:
|
74
|
+
```
|
75
|
+
curl -k --cacert insecure_ca.pem -x http://localhost:7777 https://httpbin.org/get
|
76
|
+
```
|
51
77
|
|
52
78
|
## Development
|
53
79
|
|
@@ -57,7 +83,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
57
83
|
|
58
84
|
## Contributing
|
59
85
|
|
60
|
-
|
86
|
+
|
61
87
|
|
62
88
|
## License
|
63
89
|
|
data/lib/inspect_request.rb
CHANGED
@@ -1,40 +1,75 @@
|
|
1
1
|
require 'inspect_request/version'
|
2
2
|
require 'ritm'
|
3
3
|
|
4
|
+
# You can create multiple Checker instances (verificator). But it will share the same proxy.
|
4
5
|
module InspectRequest
|
5
|
-
|
6
|
-
@session = nil
|
7
|
-
|
6
|
+
# Checker class
|
8
7
|
class Checker
|
8
|
+
@started = false
|
9
|
+
@session = nil
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :session
|
13
|
+
attr_reader :started
|
14
|
+
end
|
15
|
+
|
9
16
|
def initialize
|
10
|
-
|
17
|
+
@results = []
|
18
|
+
@verifier_block = proc {}
|
11
19
|
|
12
|
-
|
20
|
+
self.class.start
|
21
|
+
self.class.session.on_request do |req|
|
13
22
|
track_result @verifier_block.call req.clone
|
14
23
|
end
|
24
|
+
end
|
15
25
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
26
|
+
# Start the proxy. No need to do this unless you've explicitely shut it down
|
27
|
+
def self.start
|
28
|
+
return if @started
|
29
|
+
@session ||= Ritm::Session.new
|
30
|
+
@session.start
|
31
|
+
@started = true
|
32
|
+
trap('INT') { Checker.shutdown }
|
33
|
+
trap('TERM') { Checker.shutdown }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Shutdown proxy
|
37
|
+
def self.shutdown
|
38
|
+
@session.shutdown if @started
|
39
|
+
@started = false
|
20
40
|
end
|
21
41
|
|
22
|
-
|
42
|
+
def started?
|
43
|
+
self.class.started
|
44
|
+
end
|
45
|
+
|
46
|
+
# block should return true/false given an +req+ (webrick request instance)
|
47
|
+
# ===== Examples
|
48
|
+
#
|
49
|
+
# foo.verify do |req|
|
50
|
+
# req.host == 'example.org'
|
51
|
+
# end
|
23
52
|
def verify(&block)
|
24
53
|
@verifier_block = block
|
25
54
|
end
|
26
55
|
|
27
|
-
#
|
56
|
+
# did our verification ever fulfilled?
|
28
57
|
def fulfilled?
|
29
58
|
res = @results.any? # any true?
|
30
59
|
@results.clear
|
31
60
|
res
|
32
61
|
end
|
33
62
|
|
63
|
+
# Configure proxy. It will also auto-restart the proxy
|
64
|
+
# ==== Examples
|
65
|
+
# foo = InspectRequest::Checker.new
|
66
|
+
# foo.configure do
|
67
|
+
# proxy[:bind_port] = 7070
|
68
|
+
# end
|
34
69
|
def configure(&block)
|
35
|
-
|
36
|
-
|
37
|
-
|
70
|
+
self.class.session.send(:configure, &block)
|
71
|
+
self.class.session.shutdown
|
72
|
+
self.class.session.start
|
38
73
|
end
|
39
74
|
|
40
75
|
private
|
@@ -43,29 +78,4 @@ module InspectRequest
|
|
43
78
|
@results.push result
|
44
79
|
end
|
45
80
|
end
|
46
|
-
|
47
|
-
# Your code goes here...
|
48
|
-
def self.start
|
49
|
-
return if @started
|
50
|
-
@session = Ritm::Session.new
|
51
|
-
@session.configure do
|
52
|
-
proxy[:bind_address] = '0.0.0.0'
|
53
|
-
proxy[:bind_port] = 7777
|
54
|
-
end
|
55
|
-
@session.start
|
56
|
-
@started = true
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.shutdown
|
60
|
-
@session.shutdown if @started
|
61
|
-
@started = false
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.started?
|
65
|
-
@started
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.session
|
69
|
-
@session
|
70
|
-
end
|
71
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspect_request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akhmad Fathonih
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ritm
|