json_schemer-fuzz 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/CHANGELOG.md +19 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/CONTRIBUTING.md +47 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +221 -0
  8. data/SECURITY.md +13 -0
  9. data/lib/json_schemer/fuzz/keyword/additional_properties.rb +60 -0
  10. data/lib/json_schemer/fuzz/keyword/all_of.rb +46 -0
  11. data/lib/json_schemer/fuzz/keyword/any_of.rb +43 -0
  12. data/lib/json_schemer/fuzz/keyword/dependencies.rb +49 -0
  13. data/lib/json_schemer/fuzz/keyword/enum.rb +32 -0
  14. data/lib/json_schemer/fuzz/keyword/format.rb +119 -0
  15. data/lib/json_schemer/fuzz/keyword/items.rb +67 -0
  16. data/lib/json_schemer/fuzz/keyword/max_items.rb +43 -0
  17. data/lib/json_schemer/fuzz/keyword/max_length.rb +28 -0
  18. data/lib/json_schemer/fuzz/keyword/max_properties.rb +43 -0
  19. data/lib/json_schemer/fuzz/keyword/maximum.rb +44 -0
  20. data/lib/json_schemer/fuzz/keyword/min_items.rb +42 -0
  21. data/lib/json_schemer/fuzz/keyword/min_length.rb +27 -0
  22. data/lib/json_schemer/fuzz/keyword/min_properties.rb +37 -0
  23. data/lib/json_schemer/fuzz/keyword/minimum.rb +43 -0
  24. data/lib/json_schemer/fuzz/keyword/multiple_of.rb +27 -0
  25. data/lib/json_schemer/fuzz/keyword/not.rb +26 -0
  26. data/lib/json_schemer/fuzz/keyword/one_of.rb +74 -0
  27. data/lib/json_schemer/fuzz/keyword/pattern.rb +17 -0
  28. data/lib/json_schemer/fuzz/keyword/properties.rb +38 -0
  29. data/lib/json_schemer/fuzz/keyword/required.rb +39 -0
  30. data/lib/json_schemer/fuzz/keyword/unique_items.rb +31 -0
  31. data/lib/json_schemer/fuzz/keyword.rb +29 -0
  32. data/lib/json_schemer/fuzz/primitive_type/array.rb +50 -0
  33. data/lib/json_schemer/fuzz/primitive_type/boolean.rb +29 -0
  34. data/lib/json_schemer/fuzz/primitive_type/integer.rb +55 -0
  35. data/lib/json_schemer/fuzz/primitive_type/null.rb +30 -0
  36. data/lib/json_schemer/fuzz/primitive_type/number.rb +50 -0
  37. data/lib/json_schemer/fuzz/primitive_type/object.rb +54 -0
  38. data/lib/json_schemer/fuzz/primitive_type/string.rb +50 -0
  39. data/lib/json_schemer/fuzz/primitive_type.rb +31 -0
  40. data/lib/json_schemer/fuzz/version.rb +7 -0
  41. data/lib/json_schemer/fuzz.rb +170 -0
  42. data/lib/json_schemer-fuzz.rb +7 -0
  43. data.tar.gz.sig +0 -0
  44. metadata +387 -0
  45. metadata.gz.sig +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 62f662b36741fb1938e60b345632d1596f8f6e20d8ab90e0b1064002ed247196
4
+ data.tar.gz: d0b6d4387b36ded1f67f6a471530271dfcac24bf27ad8eb9fc90232a5c31fd19
5
+ SHA512:
6
+ metadata.gz: 59a5530e38151c797ade608c48d5f4d1bb9a84e23635439cf61319edcca6f6ed5e608a022dda961f8b9c49a699331c9592ee6d2196f56dd75b10621f2c95edea
7
+ data.tar.gz: 56a3edeb52183c56f3ccc0dd834c262e35b5e77ffb2d87e143eaa2c1ab3d9fee5d82fd20e5807c3cb96ad8f9cebd4c2d6e1400a2219bdb4ec4a4e1348125a7de
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ n����oo�0
2
+ �ѫ��t�����\/�+��v~����M���H)5�n7M nz� ���� ���3�j6vvޗ�nրu=��J��*I��mh "*�;��ʬ����Q���Jc�l�4�8�3PNU���+*�CFѠ�tc��y�r��›��RE���-:�qGˡ�:�����<m�N���2�.�U>^��@�@�pg�<!n�Ko֐R��LQ"я��_
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+ ### Added
10
+ ### Changed
11
+ ### Fixed
12
+ ### Removed
13
+
14
+ ## [1.0.0] - 2023-10-26
15
+ ### Added
16
+ - Initial release
17
+
18
+ [Unreleased]: https://github.com/pboling/json_schemer-fuzz/v1.0.0...HEAD
19
+ [1.0.0]: https://github.com/pboling/json_schemer-fuzz/compare/65fe2002d16ede8c5d2dab11b82ac20dab9000e2...v1.0.0
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at peter.boling@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,47 @@
1
+ ## Contributing
2
+
3
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/pboling/json_schemer-fuzz][🚎src-main]
4
+ . This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
5
+ the [code of conduct][🤝conduct].
6
+
7
+ To submit a patch, please fork the project and create a patch with tests. Once you're happy with it send a pull request
8
+ and post a message to the [gitter chat][🏘chat].
9
+
10
+ ## Release
11
+
12
+ To release a new version:
13
+
14
+ 1. Run `bin/setup && bin/rake` as a tests, coverage, & linting sanity check
15
+ 2. Update the version number in `version.rb`
16
+ 3. Run `bin/setup && bin/rake` again as a secondary check, and to update `Gemfile.lock`
17
+ 4. Run `git commit -am "🔖 Prepare release v<VERSION>"` to commit the changes
18
+ a. NOTE: Remember to [check the build][🧪build]!
19
+ 5. Run `git push` to trigger the final CI pipeline before release, & merge PRs
20
+ 6. Run `git checkout main` (Or whichever branch is considered `trunk`, e.g. `master`)
21
+ 7. Run `git pull origin main` to ensure you will release the latest trunk code.
22
+ 8. Set `SOURCE_DATE_EPOCH` so `rake build` and `rake release` use same timestamp, and generate same checksums
23
+ a. Run `export SOURCE_DATE_EPOCH=$EPOCHSECONDS`
24
+ 9. Run `bundle exec rake build`
25
+ 10. Run [`bin/checksums`](https://github.com/rubygems/guides/pull/325) to create SHA-256 and SHA-512 checksums
26
+ a. Checksums will be committed automatically by the script, but not pushed
27
+ 11. Run `bundle exec rake release` which will create a git tag for the version,
28
+ push git commits and tags, and push the `.gem` file to [rubygems.org][💎rubygems]
29
+
30
+ NOTE: You will need to have a public key in `certs/`, and list your cert in the
31
+ `gemspec`, in order to sign the new release.
32
+ See: [RubyGems Security Guide][🔒️rubygems-security-guide]
33
+
34
+ ## Contributors
35
+
36
+ [![Contributors](https://contrib.rocks/image?repo=pboling/json_schemer-fuzz)][🖐contributors]
37
+
38
+ Made with [contributors-img][🖐contrib-rocks].
39
+
40
+ [🧪build]: https://github.com/pboling/json_schemer-fuzz/actions
41
+ [🏘chat]: https://matrix.to/#/%23pboling_json_schemer-fuzz:gitter.im
42
+ [🤝conduct]: https://github.com/pboling/json_schemer-fuzz/blob/main/CODE_OF_CONDUCT.md
43
+ [🖐contrib-rocks]: https://contrib.rocks
44
+ [🖐contributors]: https://github.com/pboling/json_schemer-fuzz/graphs/contributors
45
+ [💎rubygems]: https://rubygems.org
46
+ [🔒️rubygems-security-guide]: https://guides.rubygems.org/security/#building-gems
47
+ [🚎src-main]: https://github.com/pboling/json_schemer-fuzz
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2015 Naoki Shimizu
4
+ Copyright (c) 2023 Peter Boling (railsbling.com)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # JSONSchemer::Fuzz
2
+
3
+ A JSON FUZZ Generator in Ruby from JSON Schema files.
4
+
5
+ This gem is a re-write & renaming of dead-since-2015 [`json-fuzz-generator`](https://github.com/deme0607/json-fuzz-generator),
6
+ It has been re-built on top of the modern [`json_schemer`](https://github.com/davishmcclurg/json_schemer)
7
+ instead of the unmaintained `json-schema`.
8
+
9
+ <div id="badges">
10
+
11
+ [![Test Coverage][🔑cc-covi]][🔑cc-cov]
12
+ [![Maintainability][🔑cc-mnti]][🔑cc-mnt]
13
+ [![Depfu][🔑depfui]][🔑depfu]
14
+
15
+ -----
16
+
17
+ [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay]
18
+ [![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor]
19
+ <span class="badge-buymeacoffee">
20
+ <a href="https://ko-fi.com/O5O86SNP4" target='_blank' title="Donate to my FLOSS or refugee efforts at ko-fi.com"><img src="https://img.shields.io/badge/buy%20me%20coffee-donate-yellow.svg" alt="Buy me coffee donation button" /></a>
21
+ </span>
22
+ <span class="badge-patreon">
23
+ <a href="https://patreon.com/galtzo" title="Donate to my FLOSS or refugee efforts using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a>
24
+ </span>
25
+
26
+ </div>
27
+
28
+ [⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
29
+ [⛳liberapay]: https://liberapay.com/pboling/donate
30
+ [🖇sponsor-img]: https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github
31
+ [🖇sponsor]: https://github.com/sponsors/pboling
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ gem 'json_schemer-fuzz'
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install json_schemer-fuzz
46
+
47
+ ## Usage
48
+
49
+ ### generate valid param
50
+
51
+ ```ruby
52
+ require "json_schema-fuzz"
53
+
54
+ json = <<~JSON
55
+ {
56
+ "title": "Basic Schema",
57
+ "type": "object",
58
+ "properties": {
59
+ "id" : {
60
+ "type": "integer",
61
+ "minimum": 0
62
+ },
63
+ "name": {
64
+ "type": "string"
65
+ },
66
+ "birthday": {
67
+ "type": "string",
68
+ "format": "date"
69
+ }
70
+ }
71
+ }
72
+ JSON
73
+
74
+ schema = JSON.parse(json)
75
+ JSONSchemer::Fuzz.default_param(schema)
76
+ # => {"id"=>0, "name"=>"hoge", "birthday"=>"1992-06-27"}
77
+ ```
78
+
79
+ ### generate invalid params
80
+
81
+ ```ruby
82
+ require "json_schema-fuzz"
83
+
84
+ json = <<~JSON
85
+ {
86
+ "title": "Basic Schema",
87
+ "type": "object",
88
+ "properties": {
89
+ "id" : {
90
+ "type": "integer",
91
+ "minimum": 0
92
+ },
93
+ "name": {
94
+ "type": "string"
95
+ },
96
+ "birthday": {
97
+ "type": "string",
98
+ "format": "date"
99
+ }
100
+ }
101
+ }
102
+ JSON
103
+ schema = JSON.parse(json)
104
+ JSONSchemer::Fuzz.generate(schema)
105
+ # => [
106
+ # ["sample", "array"],
107
+ # false,
108
+ # 83,
109
+ # nil,
110
+ # 0.8182545022111043,
111
+ # "hoge",
112
+ # {"id"=>"&", "name"=>"hoge", "birthday"=>"1992-06-27"},
113
+ # {"id"=>[0.1], "name"=>"hoge", "birthday"=>"1992-06-27"},
114
+ # {"id"=>["sample", "array"], "name"=>"hoge", "birthday"=>"1992-06-27"},
115
+ # {"id"=>false, "name"=>"hoge", "birthday"=>"1992-06-27"},
116
+ # {"id"=>nil, "name"=>"hoge", "birthday"=>"1992-06-27"},
117
+ # {"id"=>0.0, "name"=>"hoge", "birthday"=>"1992-06-27"},
118
+ # {"id"=>{}, "name"=>"hoge", "birthday"=>"1992-06-27"},
119
+ # {"id"=>"hoge", "name"=>"hoge", "birthday"=>"1992-06-27"},
120
+ # {"id"=>-1, "name"=>"hoge", "birthday"=>"1992-06-27"},
121
+ # {"id"=>0, "name"=>["sample", "array"], "birthday"=>"1992-06-27"},
122
+ # {"id"=>0, "name"=>true, "birthday"=>"1992-06-27"},
123
+ # {"id"=>0, "name"=>30, "birthday"=>"1992-06-27"},
124
+ # {"id"=>0, "name"=>nil, "birthday"=>"1992-06-27"},
125
+ # {"id"=>0, "name"=>0.8849255474901346, "birthday"=>"1992-06-27"},
126
+ # {"id"=>0, "name"=>{}, "birthday"=>"1992-06-27"},
127
+ # {"id"=>0, "name"=>"hoge", "birthday"=>["sample", "array"]},
128
+ # {"id"=>0, "name"=>"hoge", "birthday"=>true},
129
+ # {"id"=>0, "name"=>"hoge", "birthday"=>62},
130
+ # {"id"=>0, "name"=>"hoge", "birthday"=>nil},
131
+ # {"id"=>0, "name"=>"hoge", "birthday"=>0.05006772646327107},
132
+ # {"id"=>0, "name"=>"hoge", "birthday"=>{}},
133
+ # {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-32"},
134
+ # {"id"=>0, "name"=>"hoge", "birthday"=>"n2010-01-01"},
135
+ # {"id"=>0, "name"=>"hoge", "birthday"=>"2010-1-01"},
136
+ # {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-1"},
137
+ # {"id"=>0, "name"=>"hoge", "birthday"=>"2010-01-01n"}
138
+ # ]
139
+ ```
140
+
141
+ ## Development
142
+
143
+ Run tests!
144
+
145
+ ```shell
146
+ bundle install
147
+ bundle exec rake
148
+ ```
149
+
150
+ ## Contributing
151
+
152
+ See [CONTRIBUTING.md][🪇conduct]
153
+
154
+ [🪇conduct]: CONTRIBUTING.md
155
+
156
+ ## 🪇 Code of Conduct
157
+
158
+ Everyone interacting in this project's codebases, issue trackers,
159
+ chat rooms and mailing lists is expected to follow the [code of conduct][🪇conduct].
160
+
161
+ [🪇conduct]: CODE_OF_CONDUCT.md
162
+
163
+ ## 📌 Versioning
164
+
165
+ This Library adheres to [Semantic Versioning 2.0.0][📌semver].
166
+ Violations of this scheme should be reported as bugs.
167
+ Specifically, if a minor or patch version is released that breaks backward compatibility,
168
+ a new version should be immediately released that restores compatibility.
169
+ Breaking changes to the public API will only be introduced with new major versions.
170
+
171
+ To get a better understanding of how SemVer is intended to work over a project's lifetime,
172
+ read this article from the creator of SemVer:
173
+
174
+ - ["Major Version Numbers are Not Sacred"][📌major-versions-not-sacred]
175
+
176
+ As a result of this policy, you can (and should) specify a dependency on these libraries using
177
+ the [Pessimistic Version Constraint][📌pvc] with two digits of precision.
178
+
179
+ For example:
180
+
181
+ ```ruby
182
+ spec.add_dependency("json_schemer-fuzz", "~> 1.0")
183
+ ```
184
+
185
+ [comment]: <> ( VERSIONING LINKS )
186
+
187
+ [📌pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
188
+ [📌semver]: http://semver.org/
189
+ [📌major-versions-not-sacred]: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html
190
+
191
+ ## 📄 License
192
+
193
+ The gem is available as open source under the terms of
194
+ the [MIT License][📄license] [![License: MIT][📄license-img]][📄license-ref].
195
+ See [LICENSE.txt][📄license] for the official [Copyright Notice][📄copyright-notice-explainer].
196
+
197
+ [comment]: <> ( LEGAL LINKS )
198
+
199
+ [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
200
+ [📄license]: LICENSE.txt
201
+ [📄license-ref]: https://opensource.org/licenses/MIT
202
+ [📄license-img]: https://img.shields.io/badge/License-MIT-green.svg
203
+
204
+ ### © Copyright
205
+
206
+ * Copyright © 2014-2015 Naoki Shimizu
207
+ * Copyright © 2023 [Peter H. Boling][💁🏼‍️peterboling] of [Rails Bling][💁🏼‍️railsbling]
208
+
209
+ [comment]: <> ( COPYRIGHT LINKS )
210
+
211
+ [💁🏼‍️peterboling]: http://www.peterboling.com
212
+ [💁🏼‍️railsbling]: http://www.railsbling.com
213
+
214
+ [comment]: <> ( KEYED LINKS )
215
+
216
+ [🔑cc-mnt]: https://codeclimate.com/github/pboling/json_schemer-fuzz/maintainability
217
+ [🔑cc-mnti]: https://api.codeclimate.com/v1/badges/f39a86da0075bb88872a/maintainability
218
+ [🔑cc-cov]: https://codeclimate.com/github/pboling/json_schemer-fuzz/test_coverage
219
+ [🔑cc-covi]: https://api.codeclimate.com/v1/badges/f39a86da0075bb88872a/test_coverage
220
+ [🔑depfu]: https://depfu.com/github/pboling/json_schemer-fuzz?project_id=39376
221
+ [🔑depfui]: https://badges.depfu.com/badges/b44af6cec217d3436e0782ed6d9a3324/count.svg
data/SECURITY.md ADDED
@@ -0,0 +1,13 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |---------|-----------|
7
+ | 1.x | ✅ |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ Peter Boling is the primary maintainer of this gem. Please find a way
12
+ to [contact him directly](https://railsbling.com/contact) to report the issue. Include as much relevant information as
13
+ possible.
@@ -0,0 +1,60 @@
1
+ module JSONSchemer
2
+ module Fuzz
3
+ class Keyword
4
+ class AdditionalProperties
5
+ class << self
6
+ # @return Array
7
+ def invalid_params(attributes)
8
+ attributes = Marshal.load(Marshal.dump(attributes))
9
+ additional_properties = attributes.delete("additionalProperties")
10
+ raise "No additionalProperties keyword given: #{attributes}" if additional_properties.nil?
11
+
12
+ template = JSONSchemer::Fuzz.default_param(attributes)
13
+
14
+ additional_key = nil
15
+ until additional_key
16
+ key = /\w+/.gen
17
+ additional_key = key unless template.key?(key)
18
+ end
19
+
20
+ if additional_properties
21
+ additional_param = JSONSchemer::Fuzz.generate(additional_properties).sample
22
+ template[additional_key] = additional_param
23
+ else
24
+ template[additional_key] = template[template.keys.sample]
25
+ end
26
+
27
+ [template]
28
+ end
29
+
30
+ # @return Hash
31
+ def valid_param(attributes)
32
+ attributes = Marshal.load(Marshal.dump(attributes))
33
+ additional_properties = attributes.delete("additionalProperties")
34
+ raise "No additionalProperties keyword given: #{attributes}" if additional_properties.nil?
35
+
36
+ template = JSONSchemer::Fuzz.default_param(attributes)
37
+
38
+ if additional_properties
39
+ additional_param = if additional_properties.instance_of?(Hash)
40
+ JSONSchemer::Fuzz.default_param(additional_properties)
41
+ else
42
+ template[template.keys.sample]
43
+ end
44
+
45
+ additional_key = nil
46
+ until additional_key
47
+ key = /\w+/.gen
48
+ additional_key = key unless template.key?(key)
49
+ end
50
+
51
+ template[additional_key] = additional_param
52
+ end
53
+
54
+ template
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ module JSONSchemer
2
+ module Fuzz
3
+ class Keyword
4
+ class AllOf
5
+ class << self
6
+ # @return Array
7
+ def invalid_params(attributes)
8
+ all_of = attributes["allOf"]
9
+ raise "No allOf keyword given: #{attributes}" unless all_of
10
+
11
+ generated_params = []
12
+
13
+ all_of.each do |schema|
14
+ JSONSchemer::Fuzz.generate(schema).each do |invalid_param|
15
+ if invalid_param.empty?
16
+ generated_params << invalid_param
17
+ else
18
+ template = valid_param(attributes)
19
+ template.merge!(invalid_param)
20
+ generated_params << template
21
+ end
22
+ end
23
+ end
24
+
25
+ generated_params
26
+ end
27
+
28
+ # @return Hash
29
+ def valid_param(attributes)
30
+ attributes = Marshal.load(Marshal.dump(attributes))
31
+ all_of = attributes.delete("allOf")
32
+ raise "No allOf keyword given: #{attributes}" unless all_of
33
+
34
+ generated_param = {}
35
+
36
+ all_of.each do |schema|
37
+ generated_param.merge!(JSONSchemer::Fuzz.default_param(schema))
38
+ end
39
+
40
+ generated_param
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ module JSONSchemer
2
+ module Fuzz
3
+ class Keyword
4
+ class AnyOf
5
+ class << self
6
+ # @return Array
7
+ def invalid_params(attributes)
8
+ any_of = attributes["anyOf"]
9
+ raise "No anyOf keyword given: #{attributes}" unless any_of
10
+
11
+ generated_params = []
12
+
13
+ any_of.each do |schema|
14
+ temp_params = JSONSchemer::Fuzz.generate(schema).reject do |param|
15
+ ::JSONSchemer.schema(attributes).validate(param)
16
+ end
17
+ temp_params.each { |e| generated_params << e }
18
+ end
19
+
20
+ raise "failed to generate invalid_params for schema: #{attributes}" if generated_params.empty?
21
+ generated_params.uniq
22
+ end
23
+
24
+ # @return Hash
25
+ def valid_param(attributes)
26
+ attributes = Marshal.load(Marshal.dump(attributes))
27
+ any_of = attributes.delete("anyOf")
28
+ raise "No anyOf keyword given: #{attributes}" unless any_of
29
+
30
+ generated_params = []
31
+
32
+ any_of.each do |valid_schema|
33
+ generated_param = JSONSchemer::Fuzz.default_param(valid_schema)
34
+ generated_params << generated_param
35
+ end
36
+
37
+ generated_params.sample
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ module JSONSchemer
2
+ module Fuzz
3
+ class Keyword
4
+ class Dependencies
5
+ class << self
6
+ # @return Array
7
+ def invalid_params(attributes)
8
+ attributes = Marshal.load(Marshal.dump(attributes))
9
+ dependencies = attributes.delete("dependencies")
10
+ raise "No dependencies keyword given: #{attributes}" unless dependencies
11
+
12
+ generated_params = []
13
+ template = JSONSchemer::Fuzz.default_param(attributes)
14
+
15
+ dependencies.each do |key, dependency|
16
+ dependency.each do |required_key|
17
+ invalid_param = Marshal.load(Marshal.dump(template))
18
+ invalid_param.delete(required_key)
19
+ generated_params << invalid_param
20
+ end
21
+ end
22
+
23
+ generated_params
24
+ end
25
+
26
+ # @return Hash
27
+ def valid_param(attributes)
28
+ attributes = Marshal.load(Marshal.dump(attributes))
29
+ dependencies = attributes.delete("dependencies")
30
+ raise "No dependencies keyword given: #{attributes}" unless dependencies
31
+
32
+ generated_params = []
33
+
34
+ dependencies.each do |key, dependency|
35
+ template = JSONSchemer::Fuzz.default_param(attributes)
36
+ template[key] = "hoge" if template.keys.size == 0
37
+ dependency.each do |required_key|
38
+ template.merge!(required_key => template[template.keys.sample]) unless template.key?(required_key)
39
+ generated_params << template
40
+ end
41
+ end
42
+
43
+ generated_params.sample
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ module JSONSchemer
2
+ module Fuzz
3
+ class Keyword
4
+ class Enum
5
+ class << self
6
+ # @return Array
7
+ def invalid_params(attributes)
8
+ attributes = Marshal.load(Marshal.dump(attributes))
9
+ enum = attributes.delete("enum")
10
+ raise "No enum keyword given: #{attributes}" unless enum
11
+
12
+ generated_params = []
13
+ JSONSchemer::Fuzz::GENERATOR_MAP.each do |type, klass|
14
+ klass.invalid_params(attributes).each do |invalid_param|
15
+ generated_params << invalid_param unless enum.include?(invalid_param)
16
+ end
17
+ end
18
+
19
+ generated_params.empty? ? [nil] : generated_params
20
+ end
21
+
22
+ def valid_param(attributes)
23
+ enum = attributes["enum"]
24
+ raise "No enum keyword given: #{attributes}" unless enum
25
+
26
+ enum.sample
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end