clumsy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 201ddce02cc0dd4d4e17a09db9c58b3a4a0f92a2
4
+ data.tar.gz: 15056852659864a130bb0f98cd2dac2eaee951a4
5
+ SHA512:
6
+ metadata.gz: 457c2b1bdf27bcc21628ee43817361df4966ab6dda40e7173270b72fc9ba32dd2f986c844111289f24447c4459ae1e95792ce564800c59957003b4fcc9540108
7
+ data.tar.gz: 7f0a0388e18988981d42680a348d10e9cafa175c22878fad8092f48b3eb3412757ba2ee3538bef521cdc9d95b69bc1b7d514ab75717a4c061f7de15b71d76509
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clumsy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Darby Frey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # Clumsy
2
+
3
+ An awkward tool for testing proxies with ngrok.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'clumsy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install clumsy
20
+
21
+ ## Usage
22
+
23
+ Please note: This project is very new and likely has bugs. Contributions are very welcome!
24
+
25
+ Clumsy is a tool for testing proxies in an end-to-end fashion. The idea for this came about around a need to build tests for API gateway tools like Apigee or Amazon API Gateway. Because of the nature of these envronments, there isn't an easy way to test the implementation without deploying a server. Clumsy works by using a deployed *test* instance of a server and piping that output back to the testing machine using [ngrok](https://ngrok.com/). This allows the test to trigger a request and receive the output within the same process.
26
+
27
+ **Prerequisites:**
28
+
29
+ * A running ngrok tunnel
30
+ * A running instance of your proxy, pointing to your [ngrok](https://ngrok.com/) tunnel
31
+ * A ruby test environment (rspec, etc.)
32
+ * A [clumsy test](#clumsy-test-file-structure) file to describe your test
33
+
34
+ With all of that in place, you can setup a test like this:
35
+
36
+ ```ruby
37
+ describe 'Some Context' do
38
+
39
+ it 'does what you expect' do
40
+
41
+ test_file = Clumsy::TestFile.new('path/to/test_file')
42
+
43
+ server = Clumsy::Server.new(test_file)
44
+ server.start!
45
+
46
+ runner = Clumsy::TestRunner.new(server, test_file)
47
+ runner.process
48
+
49
+ expect(server.did_receive_request('GET http://something.ngrok.com/foo/bar')).to be true
50
+
51
+ end
52
+
53
+ end
54
+ ```
55
+
56
+
57
+
58
+ ## Clumsy Test File Structure
59
+
60
+ ```json
61
+ {
62
+ "request_method":"GET",
63
+ "request_url":"REQUEST_URL",
64
+ "downstream": [
65
+ {
66
+ "request": {
67
+ "method":"GET",
68
+ "url":"DOWNSTREAM_REQUEST_URL_1"
69
+ },
70
+ "response": {
71
+ "payload": "JSON PAYLOAD"
72
+ }
73
+ },
74
+ {
75
+ "request": {
76
+ "method":"GET",
77
+ "url":"DOWNSTREAM_REQUEST_URL_2"
78
+ },
79
+ "response":{
80
+ "payload": "JSON PAYLOAD"
81
+ }
82
+ },
83
+ {
84
+ "request":{
85
+ "method":"GET",
86
+ "url":"DOWNSTREAM_REQUEST_URL_3"
87
+ },
88
+ "response":{
89
+ "payload": "JSON PAYLOAD"
90
+ }
91
+ },
92
+ {
93
+ "request":{
94
+ "method":"GET",
95
+ "url":"DOWNSTREAM_REQUEST_URL_4"
96
+ },
97
+ "response":{
98
+ "payload": "JSON PAYLOAD"
99
+ }
100
+ }
101
+ ],
102
+ "response":{
103
+ "status":200,
104
+ "headers":"",
105
+ "body":{
106
+ "payload": "FINAL JSON PAYLOAD"
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+
113
+ ## Development
114
+
115
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
116
+
117
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome on GitHub at https://github.com/darbyfrey/clumsy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
122
+
123
+
124
+ ## License
125
+
126
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
127
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "clumsy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/clumsy.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clumsy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clumsy"
8
+ spec.version = Clumsy::VERSION
9
+ spec.authors = ["Darby Frey"]
10
+ spec.email = ["darbyfrey@gmail.com"]
11
+
12
+ spec.summary = %q{A clumsy tool for end-to-end proxy testing}
13
+ spec.description = %q{A clumsy tool for end-to-end proxy testing}
14
+ spec.homepage = "https://github.com/darbyfrey/clumsy"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'rack'
23
+ spec.add_dependency 'http'
24
+ spec.add_dependency 'hashie'
25
+ spec.add_dependency 'pry'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ end
data/lib/clumsy.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'clumsy/request'
2
+ require 'clumsy/response'
3
+ require 'clumsy/server'
4
+ require 'clumsy/test_file'
5
+ require 'clumsy/test_runner'
6
+ require 'clumsy/version'
7
+ require 'http'
8
+ require 'hashie'
9
+ require 'openssl'
10
+ require 'rack'
11
+ require 'pry'
12
+
13
+ module Clumsy
14
+ end
@@ -0,0 +1,14 @@
1
+ module Clumsy
2
+ class Request
3
+ attr_reader :uri
4
+
5
+ def initialize(env)
6
+ @method = env["REQUEST_METHOD"]
7
+ @uri = env["REQUEST_URI"]
8
+ end
9
+
10
+ def to_s
11
+ "#{@method} #{@uri}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module Clumsy
2
+ class Response
3
+
4
+ def initialize(request, test_file)
5
+ @request = request
6
+ @test_file = test_file
7
+ end
8
+
9
+ def send_response
10
+ response = @test_file.downstream.select{|x| x.request.url == @request.uri}.first.response
11
+
12
+ ['200', {'Content-Type' => 'application/json'}, [response.to_json]]
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module Clumsy
2
+ class Server
3
+ attr_reader :inbound_requests
4
+
5
+ def initialize(test_file)
6
+ @test_file = test_file
7
+ @inbound_requests = Array.new
8
+ @inbound_request_strings = Array.new
9
+ @app = nil
10
+ end
11
+
12
+ def start!
13
+ app = Proc.new do |env|
14
+ request = Clumsy::Request.new(env)
15
+ response = Clumsy::Response.new(request, @test_file)
16
+ @inbound_requests << request
17
+ @inbound_request_strings << request.to_s
18
+
19
+ response.send_response
20
+ end
21
+
22
+ Thread.new do
23
+ server = Rack::Handler::WEBrick.run app
24
+ end
25
+ end
26
+
27
+ def did_receive_request(request_string)
28
+ @inbound_request_strings.include?(request_string)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Clumsy
2
+ class TestFile
3
+
4
+ def initialize(file)
5
+ begin
6
+ @file = File.read(file)
7
+ @data = Hashie::Mash.new JSON.parse(@file)
8
+ rescue Errno::ENOENT
9
+ raise 'File Not Found'
10
+ end
11
+ end
12
+
13
+ def request_method
14
+ @data.request_method
15
+ end
16
+
17
+ def request_url
18
+ @data.request_url
19
+ end
20
+
21
+ def downstream
22
+ @data.downstream
23
+ end
24
+
25
+ def response
26
+ @data.response
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module Clumsy
2
+ class TestRunner
3
+
4
+ attr_reader :response
5
+
6
+ def initialize(server, test_file)
7
+ @server = server
8
+ @test_file = test_file
9
+ end
10
+
11
+ def send_request
12
+ @response = HTTP.send(@test_file.request_method.downcase.to_sym, @test_file.request_url)
13
+ end
14
+
15
+ def process
16
+ send_request
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Clumsy
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clumsy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Darby Frey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A clumsy tool for end-to-end proxy testing
112
+ email:
113
+ - darbyfrey@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - clumsy.gemspec
129
+ - lib/clumsy.rb
130
+ - lib/clumsy/request.rb
131
+ - lib/clumsy/response.rb
132
+ - lib/clumsy/server.rb
133
+ - lib/clumsy/test_file.rb
134
+ - lib/clumsy/test_runner.rb
135
+ - lib/clumsy/version.rb
136
+ homepage: https://github.com/darbyfrey/clumsy
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.8
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: A clumsy tool for end-to-end proxy testing
160
+ test_files: []