api-tester 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +15 -0
  3. data/.github/workflows/push.yml +39 -0
  4. data/.github/workflows/test.yml +31 -0
  5. data/.rubocop.yml +61 -0
  6. data/Gemfile +2 -0
  7. data/Guardfile +70 -0
  8. data/README.md +65 -61
  9. data/Rakefile +8 -3
  10. data/api-tester.gemspec +29 -24
  11. data/changelog.txt +10 -0
  12. data/lib/api-tester.rb +6 -3
  13. data/lib/api-tester/config.rb +16 -13
  14. data/lib/api-tester/definition/boundary_case.rb +4 -1
  15. data/lib/api-tester/definition/contract.rb +8 -3
  16. data/lib/api-tester/definition/endpoint.rb +32 -23
  17. data/lib/api-tester/definition/fields/array_field.rb +20 -19
  18. data/lib/api-tester/definition/fields/boolean_field.rb +12 -9
  19. data/lib/api-tester/definition/fields/email_field.rb +14 -11
  20. data/lib/api-tester/definition/fields/enum_field.rb +14 -11
  21. data/lib/api-tester/definition/fields/field.rb +46 -45
  22. data/lib/api-tester/definition/fields/number_field.rb +11 -8
  23. data/lib/api-tester/definition/fields/object_field.rb +34 -31
  24. data/lib/api-tester/definition/fields/plain_array_field.rb +25 -0
  25. data/lib/api-tester/definition/method.rb +7 -2
  26. data/lib/api-tester/definition/request.rb +43 -16
  27. data/lib/api-tester/definition/response.rb +29 -26
  28. data/lib/api-tester/method_case_test.rb +67 -53
  29. data/lib/api-tester/modules/extra_verbs.rb +29 -9
  30. data/lib/api-tester/modules/format.rb +23 -7
  31. data/lib/api-tester/modules/good_case.rb +25 -10
  32. data/lib/api-tester/modules/injection_module.rb +32 -17
  33. data/lib/api-tester/modules/required_fields.rb +51 -0
  34. data/lib/api-tester/modules/server_information.rb +13 -10
  35. data/lib/api-tester/modules/typo.rb +36 -13
  36. data/lib/api-tester/modules/unexpected_fields.rb +61 -0
  37. data/lib/api-tester/modules/unused_fields.rb +12 -6
  38. data/lib/api-tester/reporter/api_report.rb +24 -16
  39. data/lib/api-tester/reporter/missing_field_report.rb +12 -13
  40. data/lib/api-tester/reporter/report.rb +11 -8
  41. data/lib/api-tester/reporter/status_code_report.rb +9 -2
  42. data/lib/api-tester/test_helper.rb +6 -6
  43. data/lib/api-tester/util/response_evaluator.rb +70 -57
  44. data/lib/api-tester/util/supported_verbs.rb +8 -5
  45. data/lib/api-tester/version.rb +3 -1
  46. metadata +99 -25
  47. data/.travis.yml +0 -6
  48. data/lib/api-tester/reporter/missing_response_field_report.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cab5f4e6e78d9adfebc9ebd5f0a23cdcf75c43da
4
- data.tar.gz: b6025cf9ed4dfff6290541313b8516fa1ae3918c
2
+ SHA256:
3
+ metadata.gz: 2f8866f2783c0595b22817fbd6fbaaab7a77531bf55358a50f6e0b3a62fec22a
4
+ data.tar.gz: 7aa5c6d1d261f322a8190781b62b3bc235641a7c0eec625afb1f9a9900cb4abe
5
5
  SHA512:
6
- metadata.gz: 40442ed2938bea2d1aba00b9cac4a4fc619ac560fb30cffc211f37323c12d6ba78e6cac86aecd5ffcf5822e5d3237fbd1761fba80274ac6afeaa7d1dead9c98a
7
- data.tar.gz: 1ff93796a71e53517a1af1e416d20576e85a63e503c304366a618640c694f3a25b44bf36461a12dd1e2885907525756dec6c1574e72d2b6f84328faaad072fb5
6
+ metadata.gz: 52da12901f51389ca9a4fb37d775aa8974e7514571d900fcbcfb660b6174f8251d42f6a0bb7fa9b23b3d61b01d64aa7c116c2128badf7390e2dfe106e8703ec3
7
+ data.tar.gz: 8ae063b4473b4f1fb75ceb203dc569f0e8cc16b8e9963f434bd85aad1c618daecfff77caf4a93d876b7af24cf037118635351ac98bbf82af1491b012c5c5804f
@@ -0,0 +1,15 @@
1
+ # Set update schedule for GitHub Actions
2
+
3
+ version: 2
4
+ updates:
5
+
6
+ - package-ecosystem: "github-actions"
7
+ directory: "/"
8
+ schedule:
9
+ # Check for updates to GitHub Actions every weekday
10
+ interval: "daily"
11
+
12
+ - package-ecosystem: "bundler"
13
+ directory: '/'
14
+ schedule:
15
+ interval: 'daily'
@@ -0,0 +1,39 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ workflow_dispatch
5
+
6
+ jobs:
7
+ build:
8
+ name: Build + Publish
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby 2.6
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.6.x
17
+
18
+ - name: Publish to RubyGems
19
+ run: |
20
+ mkdir -p $HOME/.gem
21
+ touch $HOME/.gem/credentials
22
+ chmod 0600 $HOME/.gem/credentials
23
+ printf -- "---\n:rubygems: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
24
+ gem build *.gemspec
25
+ gem push --KEY rubygems --host https://rubygems.org *.gem
26
+ env:
27
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
28
+
29
+ - name: Publish to GPR
30
+ run: |
31
+ mkdir -p $HOME/.gem
32
+ touch $HOME/.gem/credentials
33
+ chmod 0600 $HOME/.gem/credentials
34
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
35
+ gem build *.gemspec
36
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
37
+ env:
38
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
39
+ OWNER: ${{ github.repository_owner }}
@@ -0,0 +1,31 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Test
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
+ # uses: ruby/setup-ruby@v1
23
+ uses: ruby/setup-ruby@a195098f6b1e9074390215a49c1c14e82151a289
24
+ with:
25
+ ruby-version: 2.6
26
+ - name: Install dependencies
27
+ run: bundle install
28
+ - name: Run lint
29
+ run: bundle exec rake rubocop
30
+ - name: Run tests
31
+ run: bundle exec rake spec
@@ -0,0 +1,61 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'Guardfile'
4
+ - '*.gemspec'
5
+ - 'Rakefile'
6
+ - '**/*.rake'
7
+ - 'bin/*'
8
+
9
+ Metrics/BlockLength:
10
+ Enabled: false
11
+
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
15
+ Metrics/LineLength:
16
+ Enabled: false
17
+
18
+ Metrics/AbcSize:
19
+ Enabled: false
20
+
21
+ Metrics/ParameterLists:
22
+ Enabled: false
23
+
24
+ Naming/PredicateName:
25
+ Enabled: false
26
+
27
+ Style/IfUnlessModifier:
28
+ Enabled: false
29
+
30
+ Style/NilComparison:
31
+ Enabled: false
32
+
33
+ Style/NumericPredicate:
34
+ Enabled: false
35
+
36
+ Style/MultipleComparison:
37
+ Enabled: false
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Enabled: false
41
+
42
+ Metrics/CyclomaticComplexity:
43
+ Enabled: false
44
+
45
+ Style/BlockDelimiters:
46
+ Enabled: false
47
+
48
+ Style/EmptyLiteral:
49
+ Enabled: false
50
+
51
+ Lint/BooleanSymbol:
52
+ Enabled: false
53
+
54
+ Style/GuardClause:
55
+ Enabled: false
56
+
57
+ Naming/FileName:
58
+ Enabled: false
59
+
60
+ Style/FrozenStringLiteralComment:
61
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in api-tester.gemspec
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Api::Tester
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/api-tester.svg)](https://badge.fury.io/rb/api-tester)
3
- [![Build Status](https://travis-ci.org/araneforseti/api-tester.svg?branch=master)](https://travis-ci.org/araneforseti/api-tester)
4
+ [![Build Status](https://github.com/araneforseti/api-tester/workflows/Test/badge.svg)](https://github.com/araneforseti/api-tester/actions?query=workflow%3ATest+branch%3Amaster)
4
5
 
5
6
  Work in Progress! Use at own risk, definitely not ready
6
7
  for prime time! To isolate your project from the changes, be sure to specify which gem version you use.
@@ -13,73 +14,41 @@ relates to the unpublished gem version actively under development
13
14
 
14
15
  Check out [API Tester Example](https://github.com/araneforseti/example_api-tester) for an example in action
15
16
 
16
- # Feature Plan
17
- ## Under Development
18
- Check out our [Trello Board](https://trello.com/b/R3RtsJ2A/api-tester) to see progress and where we are headed!
19
- Feel free to leave feedback through github's issue tracker
20
-
21
- - Format module:
22
- - Checks syntax problems with the request and
23
- ensuring a consistent response
24
- - Typo module:
25
- - Tests simulates typos in the url
26
- - Extra Verbs module:
27
- - Checks all the supported verbs to ensure no vulnerabilities are exposed
28
- - Good Case (name pending) module:
29
- - Checks expected good requests will work
30
- (eg, number field should accept integers
31
- between 1 - 100)
32
- - Unused Fields module:
33
- - A module which runs after all the others and reports on any response fields which were never returned
34
-
35
- ## Intended Features Before "Release"
36
-
37
- - Other Param Testing
38
- - Path params
39
- - Query
40
- - Headers
41
- - Endpoint Testing
42
- - Unused Response Fields
43
- - Invalid method names
44
- - Invalid method types
45
- - Documentation
46
- - Generate Swagger-compliant documentation
47
- - Generate definitions from Swagger documentation
17
+ ## Out of Project Scope
48
18
 
49
- ## What is this not intended for?
19
+ - Logic testing (eg, if X is between A and B, then Y is required)
50
20
 
51
- - Logic testing (eg, if X is between A and B, then Y is
52
- required)
21
+ ## Usage
53
22
 
54
- # Usage
55
- ## Installation
23
+ ### Installation
56
24
 
57
25
  Add this line to your application's Gemfile (Note: specify your version due to gem's currently volatile nature):
58
26
 
59
27
  ```ruby
60
- gem 'api-tester', '0.0.3'
28
+ gem 'api-tester', '1.0.0'
61
29
  ```
62
30
 
63
31
  And then execute:
64
32
 
65
- $ bundle
33
+ bundle
66
34
 
67
35
  Or install it yourself as:
68
36
 
69
- $ gem install api-tester
37
+ gem install api-tester
70
38
 
71
- ## Usage in Code
39
+ ### Usage in Code
72
40
 
73
41
  Warning: This gem is still in alpha stage. Use at own risk
74
42
  understanding the contract will change until the first
75
43
  stable release
76
44
 
77
45
  Define your contract and endpoints using
46
+
78
47
  ```ruby
79
48
  require 'api-tester/definition/contract'
80
49
  require 'api-tester/definition/endpoint'
81
- contract = ApiTester::Contract.new "API Name"
82
- endpoint = ApiTester::Endpoint.new "Some name which is currently unused", "http://yourbase.com/api/endpoint"
50
+ contract = ApiTester::Contract.new "API Name", "http://yourbase.com/api"
51
+ endpoint = ApiTester::Endpoint.new "Some name which is currently unused", "/endpoint"
83
52
  ```
84
53
 
85
54
  Define methods on endpoints
@@ -87,38 +56,44 @@ Define methods on endpoints
87
56
  ```ruby
88
57
  endpoint.add_method ApiTester::SupportedVerbs::GET, expected_response, expected_request
89
58
  ```
59
+
90
60
  Note: While an extensive list of verbs exists in ApiTester::SupportedVerbs, you can define your own (with the caveat they have to be supported by RestClient)
91
61
 
92
62
  Define fields used by the method (both Request and Response)
63
+
93
64
  ```ruby
94
65
  expected_request = Request.new.add_field(ApiTester::Field.new "fieldName")
95
66
  ```
67
+
96
68
  Note: Similar to methods, you can create your own fields.
97
- They need to repond to:
69
+ They need to respond to:
70
+
98
71
  ```ruby
99
72
  field.has_subfields?
100
73
  values_array = field.negative_boundary_values
101
74
  ```
102
75
 
103
76
  Define which modules you want to use through a config
77
+
104
78
  ```ruby
105
79
  config = ApiTester::Config().with_module(Format)
106
80
  ```
107
81
 
108
82
  Put them together and call go and off you go!
83
+
109
84
  ```ruby
110
85
  request = ApiTester::Request.new.add_field(ApiTester::Field.new "fieldName")
111
86
  expected_response = ApiTester::Response.new(200).add_field(ApiTester::Field.new "fieldName")
112
- endpoint = ApiTester::Endpoint.new "Unused Name", "http://yourbase.com/api/endpoint"
87
+ endpoint = ApiTester::Endpoint.new "Unused Name", "/endpoint"
113
88
  endpoint.add_method ApiTester::SupportedVerbs::GET, expected_response, request
114
- contract = Contract.new "API Name"
89
+ contract = Contract.new "API Name", "http://yourbase.com/api"
115
90
  contract.add_endpoint endpoint
116
91
  config = ApiTester::Config().with_module(Format)
117
92
  expect(ApiTester.go(contract, config)).to be true
118
93
 
119
94
  ```
120
95
 
121
- ## Dependencies
96
+ ### Dependencies
122
97
 
123
98
  If any of your API endpoints have some setup which needs to happen before or after each call (eg, path param represents resource which needs to be created), you can use the TestHelper interface:
124
99
 
@@ -142,39 +117,55 @@ endpoint.test_helper = InfoCreator.new
142
117
  expect(tester.go).to be true
143
118
  ```
144
119
 
145
- # Modules
146
- ## Boundary
120
+ ## Modules
121
+
122
+ ### Boundary
123
+
147
124
  This module will test out various edge cases and
148
125
  ensure error handling is consistent
149
126
 
150
- ## Good Case
127
+ ### Good Case
128
+
151
129
  This module ensures your 'default request' works
152
130
  appropriately
153
131
 
154
- ## Typo
132
+ ### Typo
133
+
155
134
  This module checks for common integration issues when an
156
135
  API is first being worked against such as urls which don't
157
136
  exist
158
137
 
159
- ## Extra Verbs
138
+ ### Extra Verbs
139
+
160
140
  This module checks to ensure consistency in response when
161
141
  the api receives verbs it doesn't explicitly support
162
142
 
163
- ## Unused Fields
143
+ ### Unused Fields
144
+
164
145
  If any response fields are not returned during tests run
165
146
  by previous modules, this will fail with a report
166
147
  detailing unreturned response fields. When using this
167
148
  module, it is recommended the good case module is also
168
149
  used.
169
150
 
170
- ## Custom Modules
151
+ ### Required Fields
152
+
153
+ This module tests out all the various invalid combinations of required fields to ensure consistent response
154
+
155
+ ### Unexpected Fields
156
+
157
+ This module calls out if the API returns anything unexpected in its response
158
+
159
+ ### Custom Modules
160
+
171
161
  Do you want to do something with the definition which this gem currently does not support?
172
162
  You can create your own test module and add it to the config instance class!
173
163
  Just make sure it adheres to the following interface:
164
+
174
165
  ```ruby
175
166
  module CustomModule
176
167
  def self.go contract
177
- # Your test code here
168
+ # Your test code here
178
169
  # the contract object is the full definition created
179
170
  end
180
171
 
@@ -187,18 +178,20 @@ end
187
178
  config.with_module(CustomModule)
188
179
  ```
189
180
 
190
- # Reporting
181
+ ## Reporting
182
+
191
183
  Right now the default reporting mechanism prints out to
192
184
  the console all the issues which were found. You can
193
185
  create your own reporting class (so long as it responds
194
186
  to the same methods) or just extend the current one and
195
187
  override the print method. Then set the report
196
188
  tool in the config:
189
+
197
190
  ```ruby
198
191
  config.with_reporter(new_reporter)
199
192
  ```
200
193
 
201
- # Development
194
+ ## Development
202
195
 
203
196
  After checking out the repo, run `bin/setup` to install
204
197
  dependencies. Then, run `rake spec` to run the tests.
@@ -210,11 +203,22 @@ run `bundle exec rake install`.
210
203
 
211
204
  ## Contributing
212
205
 
213
- Bug reports and pull requests are welcome on GitHub at
214
- https://github.com/araneforseti/api-tester.
206
+ Bug reports and pull requests are welcome on [GitHub repo](https://github.com/araneforseti/api-tester).
215
207
 
208
+ ## Future Features Under Development
209
+
210
+ Check out our [Trello Board](https://trello.com/b/R3RtsJ2A/api-tester) to see progress and where we are headed!
211
+ Feel free to leave feedback through Github's issue tracker
212
+
213
+ - Other Param Testing
214
+ - Path params
215
+ - Query
216
+ - Headers
217
+ - Documentation
218
+ - Generate Swagger-compliant documentation
219
+ - Generate definitions from Swagger documentation
216
220
 
217
- # License
221
+ ## License
218
222
 
219
223
  The gem is available as open source under the terms
220
224
  of the [MIT License](http://opensource.org/licenses/MIT).