apireaper 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.gitlab-ci.yml +52 -0
- data/.rspec +2 -0
- data/CHANGELOG +7 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +3 -0
- data/LICENSE +202 -0
- data/README.md +66 -0
- data/Rakefile +22 -0
- data/apireaper.gemspec +62 -0
- data/bin/apireaper +24 -0
- data/lib/apireaper/checker.rb +132 -0
- data/lib/apireaper/cli.rb +73 -0
- data/lib/apireaper/version.rb +20 -0
- data/lib/apireaper.rb +32 -0
- data/spec/apireaper/checker_spec.rb +102 -0
- data/spec/apireaper/cli_spec.rb +33 -0
- data/spec/apireaper/stubs/servers_stubs.rb +44 -0
- data/spec/apireaper_spec.rb +23 -0
- data/spec/files/body +1 -0
- data/spec/files/fail +1 -0
- data/spec/files/schema +1 -0
- data/spec/spec_helper.rb +47 -0
- metadata +179 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9a52bdd4fbf202bceeb870138ad230d5e8233f8a
|
|
4
|
+
data.tar.gz: f236587dcbf0655e2e9477af21090aca0aa898a8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 66c2db95b9bd16449b86ef56af70cc9d711dd7df561efaaf0f8d86e848ad325d00c415d2309b4bba92acb531add97725d63885fd9e171e08b1b980a9079f955c
|
|
7
|
+
data.tar.gz: 9c6e7797822e3eb3890941dee57f0c63dd9a7d824eab0414e23d22de05416ab4705c240a68a72733f767e81fd59aa991cbed2bf57ff5c48bb62735baa00969cd
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
rubocop:
|
|
2
|
+
tags:
|
|
3
|
+
- docker
|
|
4
|
+
image: yueyehua/debian-ruby
|
|
5
|
+
stage: test
|
|
6
|
+
script:
|
|
7
|
+
- rubocop
|
|
8
|
+
|
|
9
|
+
lines_length:
|
|
10
|
+
stage: test
|
|
11
|
+
script:
|
|
12
|
+
- >
|
|
13
|
+
bash <(curl -s
|
|
14
|
+
https://gitlab.com/yue-script/checks/raw/master/check_lines_length.sh)
|
|
15
|
+
80 README.md spec/files/*
|
|
16
|
+
|
|
17
|
+
git_history:
|
|
18
|
+
stage: test
|
|
19
|
+
script:
|
|
20
|
+
- >
|
|
21
|
+
bash <(curl -s
|
|
22
|
+
https://gitlab.com/yue-script/checks/raw/master/check_git_history.sh)
|
|
23
|
+
|
|
24
|
+
before_script:
|
|
25
|
+
- bundle install
|
|
26
|
+
|
|
27
|
+
rspec:
|
|
28
|
+
tags:
|
|
29
|
+
- docker
|
|
30
|
+
image: yueyehua/debian-ruby
|
|
31
|
+
stage: test
|
|
32
|
+
script:
|
|
33
|
+
- rspec
|
|
34
|
+
artifacts:
|
|
35
|
+
paths:
|
|
36
|
+
- coverage/
|
|
37
|
+
|
|
38
|
+
pages:
|
|
39
|
+
tags:
|
|
40
|
+
- docker
|
|
41
|
+
stage: deploy
|
|
42
|
+
image: yueyehua/debian-ruby
|
|
43
|
+
dependencies:
|
|
44
|
+
- rspec
|
|
45
|
+
script:
|
|
46
|
+
- mv coverage/ public/
|
|
47
|
+
artifacts:
|
|
48
|
+
paths:
|
|
49
|
+
- public
|
|
50
|
+
expire_in: 30 days
|
|
51
|
+
only:
|
|
52
|
+
- develop
|
data/.rspec
ADDED
data/CHANGELOG
ADDED
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Contributing
|
|
2
|
+
------------
|
|
3
|
+
|
|
4
|
+
You are more than welcome to submit issues and merge requests to this project.
|
|
5
|
+
|
|
6
|
+
### Tests
|
|
7
|
+
|
|
8
|
+
Your commits must not break any tests.
|
|
9
|
+
|
|
10
|
+
### Commits format
|
|
11
|
+
|
|
12
|
+
Your commits must pass `git log --check` and messages should be formated
|
|
13
|
+
like this (based on this excellent
|
|
14
|
+
[post](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)):
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Summarize change in 50 characters or less
|
|
18
|
+
|
|
19
|
+
Provide more detail after the first line. Leave one blank line below the
|
|
20
|
+
summary and wrap all lines at 72 characters or less.
|
|
21
|
+
|
|
22
|
+
If the change fixes an issue, leave another blank line after the final
|
|
23
|
+
paragraph and indicate which issue is fixed in the specific format
|
|
24
|
+
below.
|
|
25
|
+
|
|
26
|
+
Fix #42
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Also do your best to factor commits appropriately, ie not too large with
|
|
30
|
+
unrelated things in the same commit, and not too small with the same small
|
|
31
|
+
change applied N times in N different commits. If there was some accidental
|
|
32
|
+
reformatting or whitespace changes during the course of your commits, please
|
|
33
|
+
rebase them away before submitting the MR.
|
|
34
|
+
|
|
35
|
+
### Files
|
|
36
|
+
|
|
37
|
+
All files must be 80 columns width formatted (actually 79), exception only
|
|
38
|
+
when it is really not possible.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# APIReaper
|
|
2
|
+
![License][license-img]
|
|
3
|
+
[](https://gitlab.com/vp-noc/apireaper/commits/develop)
|
|
4
|
+
[](https://gitlab.com/vp-noc/apireaper/commits/develop)
|
|
5
|
+
|
|
6
|
+
1. [Overview](#overview)
|
|
7
|
+
2. [Description](#role-description)
|
|
8
|
+
3. [Setup](#setup)
|
|
9
|
+
4. [Usage](#usage)
|
|
10
|
+
5. [Limitations](#limitations)
|
|
11
|
+
6. [Development](#development)
|
|
12
|
+
7. [Miscellaneous](#miscellaneous)
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
`APIReaper` is a simple tool to assess an API and its answer.
|
|
17
|
+
|
|
18
|
+
## Description
|
|
19
|
+
|
|
20
|
+
This tool validate if an API is able to reply to an incoming request and check
|
|
21
|
+
if the data structure sent back is valid. It requires a valid schema to compare
|
|
22
|
+
the data against.
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
$ gem install apireaper
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
An interactive help is available with:
|
|
31
|
+
|
|
32
|
+
$ apireaper help
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
To check an API:
|
|
37
|
+
|
|
38
|
+
$ apireaper check POST "<API_URL>" -h "<HEADER_KEY>:<HEADER_VALUE>" \
|
|
39
|
+
-d "<DATA_KEY>=<DATA_VALUE>" -S '<JSON_SCHEMA_OBJECT_AS_STRING>'
|
|
40
|
+
|
|
41
|
+
To check an API with a schema in a file:
|
|
42
|
+
|
|
43
|
+
$ apireaper check POST "<API_URL>" -h "<HEADER_KEY>:<HEADER_VALUE>" \
|
|
44
|
+
-d "<DATA_KEY>=<DATA_VALUE>" -F '<PATH_TO_JSON_SCHEMA_FILE>'
|
|
45
|
+
|
|
46
|
+
## Limitations
|
|
47
|
+
|
|
48
|
+
It is currently only available to validate JSON data structure.
|
|
49
|
+
More data structure may be available later.
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
Please read carefully [CONTRIBUTING.md](CONTRIBUTING.md) before making a merge
|
|
54
|
+
request.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
╚⊙ ⊙╝
|
|
58
|
+
╚═(███)═╝
|
|
59
|
+
╚═(███)═╝
|
|
60
|
+
╚═(███)═╝
|
|
61
|
+
╚═(███)═╝
|
|
62
|
+
╚═(███)═╝
|
|
63
|
+
╚═(███)═╝
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
[license-img]: https://img.shields.io/badge/license-Apache-blue.svg
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
require 'bundler/gem_tasks'
|
|
18
|
+
require 'rspec/core/rake_task'
|
|
19
|
+
|
|
20
|
+
RSpec::Core::RakeTask.new(:spec) { |task| task.verbose = false }
|
|
21
|
+
|
|
22
|
+
task default: :spec
|
data/apireaper.gemspec
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
18
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
19
|
+
require 'apireaper/version'
|
|
20
|
+
|
|
21
|
+
dev_deps = {
|
|
22
|
+
'bundler' => '~> 1.12',
|
|
23
|
+
'rspec' => '~> 3.5',
|
|
24
|
+
'rake' => '~> 11.2',
|
|
25
|
+
'rubocop' => '~> 0.43',
|
|
26
|
+
'webmock' => '~> 2.1',
|
|
27
|
+
'simplecov' => '~> 0.12'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
deps = {
|
|
31
|
+
'json-schema' => '~> 2.8',
|
|
32
|
+
'thor' => '~> 0.19'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Gem::Specification.new do |s|
|
|
36
|
+
s.name = 'apireaper'
|
|
37
|
+
s.version = APIReaper::VERSION
|
|
38
|
+
s.authors = ['Richard Delaplace']
|
|
39
|
+
s.email = 'rdelaplace@vente-privee.com'
|
|
40
|
+
s.license = 'Apache-2.0'
|
|
41
|
+
|
|
42
|
+
s.summary = 'Tool to request and check an API.'
|
|
43
|
+
s.description = 'APIReaper is a simple tool to assess an API and its answer.'
|
|
44
|
+
s.homepage = 'https://github.com/vpgrp/apireaper'
|
|
45
|
+
|
|
46
|
+
s.files = `git ls-files`.lines.map(&:chomp)
|
|
47
|
+
s.bindir = 'bin'
|
|
48
|
+
s.executables = `git ls-files bin/*`.lines.map do |exe|
|
|
49
|
+
File.basename(exe.chomp)
|
|
50
|
+
end
|
|
51
|
+
s.require_paths = ['lib']
|
|
52
|
+
|
|
53
|
+
s.required_ruby_version = '>= 2.0'
|
|
54
|
+
|
|
55
|
+
dev_deps.each_pair do |deps_gem, deps_version|
|
|
56
|
+
s.add_development_dependency deps_gem, deps_version
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
deps.each_pair do |deps_gem, deps_version|
|
|
60
|
+
s.add_dependency deps_gem, deps_version
|
|
61
|
+
end
|
|
62
|
+
end
|
data/bin/apireaper
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
Signal.trap('INT') { exit 1 }
|
|
19
|
+
|
|
20
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w[.. lib])
|
|
21
|
+
require 'rubygems'
|
|
22
|
+
require 'apireaper'
|
|
23
|
+
|
|
24
|
+
APIReaper.start
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require 'net/http'
|
|
19
|
+
require 'uri'
|
|
20
|
+
require 'json'
|
|
21
|
+
require 'json-schema'
|
|
22
|
+
|
|
23
|
+
module APIReaper
|
|
24
|
+
# This is an API response and data structure checker.
|
|
25
|
+
class Checker
|
|
26
|
+
# Class constructor method
|
|
27
|
+
def initialize(method, url, opts)
|
|
28
|
+
@method = method
|
|
29
|
+
@uri = URI.parse(url)
|
|
30
|
+
@opts = opts
|
|
31
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
|
32
|
+
@http.use_ssl = @uri.scheme.eql?('https')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Main method to run the check
|
|
36
|
+
def check
|
|
37
|
+
res = select_request
|
|
38
|
+
check_response_code(res.code)
|
|
39
|
+
check_data_structure(res.body)
|
|
40
|
+
puts 'All checks passed' unless @opts['quiet']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Check data structure
|
|
44
|
+
def check_data_structure(data)
|
|
45
|
+
JSON::Validator.validate!(find_schema_source, data)
|
|
46
|
+
puts 'Response body is valid' unless @opts['quiet']
|
|
47
|
+
rescue JSON::Schema::ValidationError => e
|
|
48
|
+
exit_with_error(10, e.message)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Check respose code
|
|
52
|
+
def check_response_code(code)
|
|
53
|
+
if code.to_i.between?(200, 299)
|
|
54
|
+
puts "Response code is valid: #{code}" unless @opts['quiet']
|
|
55
|
+
else
|
|
56
|
+
exit_with_error(11, "Response code is invalid: #{code}")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Exit with the specified errno and message
|
|
61
|
+
def exit_with_error(errno, message)
|
|
62
|
+
puts message unless @opts['quiet']
|
|
63
|
+
exit errno
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Get the data structure schema source
|
|
67
|
+
def find_schema_source
|
|
68
|
+
if @opts['schema_file'].nil?
|
|
69
|
+
JSON.parse(
|
|
70
|
+
@opts['schema'].gsub(/:([a-zA-z]+)/, '"\\1"').gsub('=>', ': ')
|
|
71
|
+
)
|
|
72
|
+
else
|
|
73
|
+
@opts['schema_file']
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Split the data string into a hash
|
|
78
|
+
def format_data
|
|
79
|
+
data = {}
|
|
80
|
+
unless @opts['data'].nil?
|
|
81
|
+
pairs = @opts['data'].split('&')
|
|
82
|
+
pairs.each do |pair|
|
|
83
|
+
(key, value) = pair.split('=')
|
|
84
|
+
data[key] = value
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
data
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# DELETE method
|
|
91
|
+
def rest_request_delete
|
|
92
|
+
exit_with_error(5, 'DELETE is not yet implemented')
|
|
93
|
+
# TODO
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# GET method
|
|
97
|
+
def rest_request_get
|
|
98
|
+
exit_with_error(5, 'GET is not yet implemented')
|
|
99
|
+
# TODO
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# POST method
|
|
103
|
+
def rest_request_post
|
|
104
|
+
req = Net::HTTP::Post.new(@uri.request_uri)
|
|
105
|
+
unless @opts['header'].nil?
|
|
106
|
+
@opts['header'].split(',').each do |h|
|
|
107
|
+
(key, value) = h.split(':')
|
|
108
|
+
req[key] = value
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
req.set_form_data(format_data)
|
|
112
|
+
@http.request(req)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# PUT method
|
|
116
|
+
def rest_request_put
|
|
117
|
+
exit_with_error(5, 'PUT is not yet implemented')
|
|
118
|
+
# TODO
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Select request method
|
|
122
|
+
def select_request
|
|
123
|
+
case @method.upcase
|
|
124
|
+
when 'DELETE' then rest_request_delete
|
|
125
|
+
when 'GET' then rest_request_get
|
|
126
|
+
when 'POST' then rest_request_post
|
|
127
|
+
when 'PUT' then rest_request_put
|
|
128
|
+
else raise "#{@method.upcase} is an unknown method"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require 'thor'
|
|
19
|
+
|
|
20
|
+
module APIReaper
|
|
21
|
+
# Simple CLI for apireaper
|
|
22
|
+
class CLI < Thor
|
|
23
|
+
desc 'version', 'Print apireaper current version'
|
|
24
|
+
def version
|
|
25
|
+
puts "APIReaper version #{APIReaper::VERSION}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc('check METHOD URL [options]',
|
|
29
|
+
'Send a request to an API and catch the reply in order to validate '\
|
|
30
|
+
'the data structure.')
|
|
31
|
+
option(
|
|
32
|
+
:header,
|
|
33
|
+
aliases: ['-h'],
|
|
34
|
+
desc: 'Http headers used with the request (comma separated). ' \
|
|
35
|
+
'<key>:<value>[,<key>:<value>[,...]]'
|
|
36
|
+
)
|
|
37
|
+
option(
|
|
38
|
+
:data,
|
|
39
|
+
aliases: ['-d'],
|
|
40
|
+
desc: 'Set of data sent with the request'
|
|
41
|
+
)
|
|
42
|
+
option(
|
|
43
|
+
:schema,
|
|
44
|
+
aliases: ['-S'],
|
|
45
|
+
default: '{"type"=>"object"}',
|
|
46
|
+
desc: 'Data structure description as formated schema'
|
|
47
|
+
)
|
|
48
|
+
option(
|
|
49
|
+
:schema_file,
|
|
50
|
+
aliases: ['-F'],
|
|
51
|
+
desc: 'Data structure description as formated schema in local file'
|
|
52
|
+
)
|
|
53
|
+
option(
|
|
54
|
+
:quiet,
|
|
55
|
+
aliases: ['-q'],
|
|
56
|
+
type: :boolean,
|
|
57
|
+
default: false,
|
|
58
|
+
desc: 'Silently do the job'
|
|
59
|
+
)
|
|
60
|
+
option(
|
|
61
|
+
:simulation,
|
|
62
|
+
aliases: ['-s'],
|
|
63
|
+
type: :boolean,
|
|
64
|
+
default: false,
|
|
65
|
+
desc: 'Simulation mode. Do nothing'
|
|
66
|
+
)
|
|
67
|
+
def check(method, url)
|
|
68
|
+
opts = options.dup
|
|
69
|
+
checker = APIReaper::Checker.new(method, url, opts)
|
|
70
|
+
checker.check unless opts['simulation']
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
module APIReaper
|
|
19
|
+
VERSION = '1.0.1'.freeze
|
|
20
|
+
end
|
data/lib/apireaper.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/urs/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
# APIReaper class
|
|
19
|
+
module APIReaper
|
|
20
|
+
class << self
|
|
21
|
+
Dir[File.join(File.dirname(__FILE__), '*', '*.rb')].each do |file|
|
|
22
|
+
require file
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def start(args = ARGV)
|
|
26
|
+
APIReaper::CLI.start(args)
|
|
27
|
+
rescue => e
|
|
28
|
+
$stderr.puts e
|
|
29
|
+
exit(1)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
require 'spec_helper'
|
|
18
|
+
|
|
19
|
+
def print_out(code)
|
|
20
|
+
case code
|
|
21
|
+
when 200, 201, 202
|
|
22
|
+
"Response code is valid: #{code}\n" \
|
|
23
|
+
"Response body is valid\n" \
|
|
24
|
+
"All checks passed\n"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe APIReaper::Checker do # rubocop:disable Metrics/BlockLength
|
|
29
|
+
%w[delete get put].each do |method|
|
|
30
|
+
context "check #{method} http://api.test.yueyehua.net/ -q" do
|
|
31
|
+
it 'tries unimplemented commands.' do
|
|
32
|
+
expect { start(self) }.to raise_error(SystemExit)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'check notexistingcmd http://api.test.yueyehua.net/ -q' do
|
|
38
|
+
it 'tries unimplemented commands.' do
|
|
39
|
+
expect { start(self) }.to raise_error(SystemExit)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'check post http://api.test.yueyehua.net/' do
|
|
44
|
+
it 'requests an API without extra arguments.' do
|
|
45
|
+
expect { start(self) }.to output(print_out(200)).to_stdout
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context 'check post http://api.test.yueyehua.net/ -d k=v' do
|
|
50
|
+
it 'requests an API with datas.' do
|
|
51
|
+
expect { start(self) }.to output(print_out(201)).to_stdout
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'check post http://api.test.yueyehua.net/ -h k:v' do
|
|
56
|
+
it 'requests an API with headers.' do
|
|
57
|
+
expect { start(self) }.to output(print_out(202)).to_stdout
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context 'check post http://api.test.yueyehua.net/ -q' do
|
|
62
|
+
it 'requests an API with quiet option.' do
|
|
63
|
+
expect { start(self) }.to output('').to_stdout
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'check post http://api.fail.yueyehua.net/ -h l:w -d l=w -q' do
|
|
68
|
+
it 'requests an API and receive 404 status code.' do
|
|
69
|
+
expect { start(self) }.to raise_error(SystemExit)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context 'check post http://api.test.yueyehua.net/ -h k:v -d k=v' do
|
|
74
|
+
it 'requests an API and test the response body without defined schema.' do
|
|
75
|
+
expect { start(self) }.to output(print_out(203)).to_stdout
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
schema_file = 'spec/files/schema'
|
|
80
|
+
opts1 = "-h k:v -d k=v -F #{schema_file}"
|
|
81
|
+
context "check post http://api.test.yueyehua.net/ #{opts1}" do
|
|
82
|
+
it 'requests an API and test the response body with schema file.' do
|
|
83
|
+
expect { start(self) }.to output(print_out(203)).to_stdout
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
schema_file = 'spec/files/schema'
|
|
88
|
+
opts2 = "-h k:v -d k=v -q -F #{schema_file}"
|
|
89
|
+
context "check post http://api.fail.yueyehua.net/ #{opts2}" do
|
|
90
|
+
it 'requests an API and test the response body with schema file.' do
|
|
91
|
+
expect { start(self) }.to raise_error(SystemExit)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
schema = JSON.parse(File.read('spec/files/schema'))
|
|
96
|
+
opts3 = "-h k:v -d k=v -S #{JSON.dump(schema)}"
|
|
97
|
+
context "check post http://api.test.yueyehua.net/ #{opts3}" do
|
|
98
|
+
it 'requests an API and test the response body with a schema as option.' do
|
|
99
|
+
expect { start(self) }.to output(print_out(203)).to_stdout
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
require 'spec_helper'
|
|
18
|
+
|
|
19
|
+
describe APIReaper::CLI do
|
|
20
|
+
context 'version' do
|
|
21
|
+
it 'prints the version.' do
|
|
22
|
+
out = "APIReaper version #{APIReaper::VERSION}\n"
|
|
23
|
+
expect { start(self) }.to output(out).to_stdout
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'notexistingcmd' do
|
|
28
|
+
it 'is an unknown command and does nothing.' do
|
|
29
|
+
out = "Could not find command \"notexistingcmd\".\n"
|
|
30
|
+
expect { start(self) }.to output(out).to_stderr
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
require 'spec_helper'
|
|
18
|
+
|
|
19
|
+
def body_file(file)
|
|
20
|
+
dir = File.dirname(__FILE__)
|
|
21
|
+
File.read(File.join(dir, '..', '..', 'files', file))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
RSpec.configure do |config|
|
|
25
|
+
config.before(:each) do
|
|
26
|
+
stub_request(:post, 'http://api.test.yueyehua.net/')
|
|
27
|
+
.to_return('status' => 200, 'body' => '{}', 'headers' => {})
|
|
28
|
+
stub_request(:post, 'http://api.test.yueyehua.net/')
|
|
29
|
+
.with('body' => { 'k' => 'v' })
|
|
30
|
+
.to_return('status' => 201, 'body' => '{}', 'headers' => {})
|
|
31
|
+
stub_request(:post, 'http://api.test.yueyehua.net/')
|
|
32
|
+
.with('headers' => { 'k' => 'v' })
|
|
33
|
+
.to_return('status' => 202, 'body' => '{}', 'headers' => {})
|
|
34
|
+
stub_request(:post, 'http://api.test.yueyehua.net/')
|
|
35
|
+
.with('body' => { 'k' => 'v' }, 'headers' => { 'k' => 'v' })
|
|
36
|
+
.to_return('status' => 203, 'body' => body_file('body'), 'headers' => {})
|
|
37
|
+
stub_request(:post, 'http://api.fail.yueyehua.net/')
|
|
38
|
+
.with('body' => { 'k' => 'v' }, 'headers' => { 'k' => 'v' })
|
|
39
|
+
.to_return('status' => 204, 'body' => body_file('fail'), 'headers' => {})
|
|
40
|
+
stub_request(:post, 'http://api.fail.yueyehua.net/')
|
|
41
|
+
.with('body' => { 'l' => 'w' }, 'headers' => { 'l' => 'w' })
|
|
42
|
+
.to_return('status' => 404, 'body' => '{}', 'headers' => {})
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
require 'spec_helper'
|
|
18
|
+
|
|
19
|
+
describe APIReaper do
|
|
20
|
+
it 'has a version number' do
|
|
21
|
+
expect(APIReaper::VERSION).not_to be nil
|
|
22
|
+
end
|
|
23
|
+
end
|
data/spec/files/body
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"h":{},"a":[],"i":10,"s":"azerty","b":true,"n":null}
|
data/spec/files/fail
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"h":null,"a":[],"i":10,"s":"azerty","b":true,"n":null}
|
data/spec/files/schema
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"object","properties":{"a":{"type":"array"},"b":{"type":"boolean"},"h":{"type":"object"},"i":{"type":"integer"},"n":{"type":"null"},"s":{"type":"string"}}}
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2017 Richard Delaplace, Vente-Privee.Com
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
require 'simplecov'
|
|
17
|
+
SimpleCov.start
|
|
18
|
+
|
|
19
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
20
|
+
require 'apireaper'
|
|
21
|
+
require 'webmock/rspec'
|
|
22
|
+
|
|
23
|
+
# Force expect syntax over should
|
|
24
|
+
RSpec.configure do |config|
|
|
25
|
+
config.expect_with :rspec do |c|
|
|
26
|
+
c.syntax = :expect
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
dir = File.dirname(__FILE__)
|
|
31
|
+
# Load helpers
|
|
32
|
+
Dir[File.join(dir, 'helpers', '*.rb')].each { |file| require file }
|
|
33
|
+
|
|
34
|
+
def now
|
|
35
|
+
Time.new.strftime('%Y-%m-%dT%H:%M:%S%z').insert(-3, ':')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Load stubs
|
|
39
|
+
files = File.join(dir, 'apireaper', 'stubs', '*.rb')
|
|
40
|
+
Dir[files].each { |file| require file }
|
|
41
|
+
|
|
42
|
+
# To test the cli
|
|
43
|
+
def start(caller_object, subcommand = nil)
|
|
44
|
+
cmd = caller_object.class.description.split(' ')
|
|
45
|
+
args = [subcommand, *cmd].compact
|
|
46
|
+
APIReaper.start(args)
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: apireaper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Richard Delaplace
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-05-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.12'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.5'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.5'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '11.2'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '11.2'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rubocop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.43'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.43'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: webmock
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '2.1'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '2.1'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: simplecov
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.12'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.12'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: json-schema
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '2.8'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '2.8'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: thor
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0.19'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0.19'
|
|
125
|
+
description: APIReaper is a simple tool to assess an API and its answer.
|
|
126
|
+
email: rdelaplace@vente-privee.com
|
|
127
|
+
executables:
|
|
128
|
+
- apireaper
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".gitlab-ci.yml"
|
|
134
|
+
- ".rspec"
|
|
135
|
+
- CHANGELOG
|
|
136
|
+
- CONTRIBUTING.md
|
|
137
|
+
- Gemfile
|
|
138
|
+
- LICENSE
|
|
139
|
+
- README.md
|
|
140
|
+
- Rakefile
|
|
141
|
+
- apireaper.gemspec
|
|
142
|
+
- bin/apireaper
|
|
143
|
+
- lib/apireaper.rb
|
|
144
|
+
- lib/apireaper/checker.rb
|
|
145
|
+
- lib/apireaper/cli.rb
|
|
146
|
+
- lib/apireaper/version.rb
|
|
147
|
+
- spec/apireaper/checker_spec.rb
|
|
148
|
+
- spec/apireaper/cli_spec.rb
|
|
149
|
+
- spec/apireaper/stubs/servers_stubs.rb
|
|
150
|
+
- spec/apireaper_spec.rb
|
|
151
|
+
- spec/files/body
|
|
152
|
+
- spec/files/fail
|
|
153
|
+
- spec/files/schema
|
|
154
|
+
- spec/spec_helper.rb
|
|
155
|
+
homepage: https://github.com/vpgrp/apireaper
|
|
156
|
+
licenses:
|
|
157
|
+
- Apache-2.0
|
|
158
|
+
metadata: {}
|
|
159
|
+
post_install_message:
|
|
160
|
+
rdoc_options: []
|
|
161
|
+
require_paths:
|
|
162
|
+
- lib
|
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
|
+
requirements:
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: '2.0'
|
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0'
|
|
173
|
+
requirements: []
|
|
174
|
+
rubyforge_project:
|
|
175
|
+
rubygems_version: 2.6.12
|
|
176
|
+
signing_key:
|
|
177
|
+
specification_version: 4
|
|
178
|
+
summary: Tool to request and check an API.
|
|
179
|
+
test_files: []
|