forest_liana 2.15.8 → 3.0.0.pre.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/controllers/forest_liana/resources_controller.rb +9 -17
  4. data/app/controllers/forest_liana/stats_controller.rb +4 -14
  5. data/app/models/forest_liana/model/action.rb +57 -3
  6. data/app/models/forest_liana/model/collection.rb +37 -9
  7. data/app/models/forest_liana/model/segment.rb +1 -1
  8. data/app/serializers/forest_liana/schema_serializer.rb +83 -0
  9. data/app/serializers/forest_liana/serializer_factory.rb +13 -48
  10. data/app/services/forest_liana/apimap_sorter.rb +88 -48
  11. data/app/services/forest_liana/base_getter.rb +1 -7
  12. data/app/services/forest_liana/has_many_getter.rb +14 -15
  13. data/app/services/forest_liana/line_stat_getter.rb +5 -1
  14. data/app/services/forest_liana/operator_value_parser.rb +1 -46
  15. data/app/services/forest_liana/pie_stat_getter.rb +2 -2
  16. data/app/services/forest_liana/query_stat_getter.rb +3 -25
  17. data/app/services/forest_liana/resource_getter.rb +8 -2
  18. data/app/services/forest_liana/resources_getter.rb +13 -27
  19. data/app/services/forest_liana/schema_adapter.rb +65 -64
  20. data/app/services/forest_liana/search_query_builder.rb +24 -5
  21. data/app/services/forest_liana/stat_getter.rb +8 -1
  22. data/app/services/forest_liana/value_stat_getter.rb +2 -2
  23. data/lib/forest_liana.rb +2 -0
  24. data/lib/forest_liana/bootstraper.rb +119 -122
  25. data/lib/forest_liana/collection.rb +41 -12
  26. data/lib/forest_liana/engine.rb +16 -11
  27. data/lib/forest_liana/json_printer.rb +54 -0
  28. data/lib/forest_liana/schema_file_updater.rb +141 -0
  29. data/lib/forest_liana/version.rb +1 -1
  30. data/test/dummy/config/routes.rb +1 -0
  31. data/test/dummy/db/test.sqlite3 +0 -0
  32. data/test/dummy/log/test.log +116056 -3826
  33. data/test/integration/navigation_test.rb +10 -0
  34. data/test/routing/route_test.rb +2 -0
  35. data/test/services/forest_liana/resources_getter_test.rb +3 -3
  36. data/test/services/forest_liana/schema_adapter_test.rb +50 -49
  37. metadata +11 -111
  38. data/app/helpers/forest_liana/query_helper.rb +0 -30
  39. data/app/helpers/forest_liana/schema_helper.rb +0 -8
  40. data/app/serializers/forest_liana/action_serializer.rb +0 -21
  41. data/app/serializers/forest_liana/collection_serializer.rb +0 -33
  42. data/app/serializers/forest_liana/segment_serializer.rb +0 -15
  43. data/app/services/forest_liana/leaderboard_stat_getter.rb +0 -44
  44. data/app/services/forest_liana/objective_stat_getter.rb +0 -10
  45. data/spec/dummy/README.rdoc +0 -28
  46. data/spec/dummy/Rakefile +0 -6
  47. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  48. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  49. data/spec/dummy/app/config/routes.rb +0 -3
  50. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  51. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  52. data/spec/dummy/app/models/island.rb +0 -5
  53. data/spec/dummy/app/models/tree.rb +0 -5
  54. data/spec/dummy/app/models/user.rb +0 -4
  55. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  56. data/spec/dummy/bin/bundle +0 -3
  57. data/spec/dummy/bin/rails +0 -4
  58. data/spec/dummy/bin/rake +0 -4
  59. data/spec/dummy/bin/setup +0 -29
  60. data/spec/dummy/config.ru +0 -4
  61. data/spec/dummy/config/application.rb +0 -26
  62. data/spec/dummy/config/boot.rb +0 -5
  63. data/spec/dummy/config/database.yml +0 -25
  64. data/spec/dummy/config/environment.rb +0 -5
  65. data/spec/dummy/config/environments/development.rb +0 -41
  66. data/spec/dummy/config/environments/production.rb +0 -79
  67. data/spec/dummy/config/environments/test.rb +0 -42
  68. data/spec/dummy/config/initializers/assets.rb +0 -11
  69. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  70. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  71. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  72. data/spec/dummy/config/initializers/forest_liana.rb +0 -2
  73. data/spec/dummy/config/initializers/inflections.rb +0 -16
  74. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  75. data/spec/dummy/config/initializers/session_store.rb +0 -3
  76. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  77. data/spec/dummy/config/routes.rb +0 -3
  78. data/spec/dummy/config/secrets.yml +0 -22
  79. data/spec/dummy/db/migrate/20190226172951_create_user.rb +0 -9
  80. data/spec/dummy/db/migrate/20190226173051_create_isle.rb +0 -10
  81. data/spec/dummy/db/migrate/20190226174951_create_tree.rb +0 -12
  82. data/spec/dummy/db/schema.rb +0 -42
  83. data/spec/dummy/db/test.sqlite3 +0 -0
  84. data/spec/dummy/log/development.log +0 -80
  85. data/spec/dummy/log/test.log +0 -26139
  86. data/spec/helpers/forest_liana/query_helper_spec.rb +0 -74
  87. data/spec/helpers/forest_liana/schema_helper_spec.rb +0 -13
  88. data/spec/rails_helper.rb +0 -61
  89. data/spec/requests/resources_spec.rb +0 -97
  90. data/spec/services/forest_liana/apimap_sorter_spec.rb +0 -172
  91. data/spec/services/forest_liana/ip_whitelist_checker_spec.rb +0 -203
  92. data/spec/services/forest_liana/schema_adapter_spec.rb +0 -17
  93. data/spec/spec_helper.rb +0 -99
@@ -1,74 +0,0 @@
1
- module ForestLiana
2
- describe QueryHelper do
3
- before(:all) do
4
- Tree.connection
5
- User.connection
6
- Island.connection
7
- end
8
-
9
- describe 'get_one_associations' do
10
- context 'on a model having 2 hasMany associations' do
11
- it 'should not return any one-one associations' do
12
- associations = QueryHelper.get_one_associations(User)
13
- expect(associations.length).to eq(0)
14
- end
15
- end
16
-
17
- context 'on a model having 3 belongsTo associations' do
18
- it 'should return the one-one associations' do
19
- associations = QueryHelper.get_one_associations(Tree)
20
- expect(associations.length).to eq(3)
21
- expect(associations.first.name).to eq(:owner)
22
- expect(associations.first.klass).to eq(User)
23
- expect(associations.second.name).to eq(:cutter)
24
- expect(associations.second.klass).to eq(User)
25
- expect(associations.third.name).to eq(:island)
26
- expect(associations.third.klass).to eq(Island)
27
- end
28
- end
29
- end
30
-
31
- describe 'get_one_association_names_symbol' do
32
- it 'should return the one-one associations names as symbols' do
33
- expect(QueryHelper.get_one_association_names_symbol(Tree)).to eq([:owner, :cutter, :island])
34
- end
35
- end
36
-
37
- describe 'get_one_association_names_string' do
38
- it 'should return the one-one associations names as strings' do
39
- expect(QueryHelper.get_one_association_names_string(Tree)).to eq(['owner', 'cutter', 'island'])
40
- end
41
- end
42
-
43
- describe 'get_tables_associated_to_relations_name' do
44
- context 'on a model having 2 hasMany associations' do
45
- it 'should return an empty hash' do
46
- tables_associated_to_relations_name =
47
- QueryHelper.get_tables_associated_to_relations_name(User)
48
- expect(tables_associated_to_relations_name.keys.length).to eq(0)
49
- end
50
- end
51
-
52
- context 'on a model having 2 belongsTo associations' do
53
- tables_associated_to_relations_name =
54
- QueryHelper.get_tables_associated_to_relations_name(Tree)
55
-
56
- it 'should return the one-one associations' do
57
- expect(tables_associated_to_relations_name.keys.length).to eq(2)
58
- end
59
-
60
- it 'should return relationships having a name different than the targeted model' do
61
- expect(tables_associated_to_relations_name['users'].length).to eq(2)
62
- expect(tables_associated_to_relations_name['users'].first).to eq(:owner)
63
- expect(tables_associated_to_relations_name['users'].second).to eq(:cutter)
64
- end
65
-
66
- it 'should return relationships on models having a custom table name' do
67
- expect(tables_associated_to_relations_name['isle'].length).to eq(1)
68
- expect(tables_associated_to_relations_name['isle'].first).to eq(:island)
69
- end
70
- end
71
- end
72
-
73
- end
74
- end
@@ -1,13 +0,0 @@
1
- module ForestLiana
2
- describe SchemaHelper do
3
- describe '#find_collection_from_model' do
4
- context 'on a simple model' do
5
- it 'should return the schema collection related to the model' do
6
- collection = SchemaHelper.find_collection_from_model(User)
7
- expect(collection.class).to eq(ForestLiana::Model::Collection)
8
- expect(collection.name).to eq('User')
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,61 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- require 'spec_helper'
3
- ENV['RAILS_ENV'] ||= 'test'
4
- require File.expand_path('../dummy/config/environment', __FILE__)
5
- # Prevent database truncation if the environment is production
6
- abort("The Rails environment is running in production mode!") if Rails.env.production?
7
- require 'rspec/rails'
8
- # Add additional requires below this line. Rails is not loaded until this point!
9
-
10
- # Requires supporting ruby files with custom matchers and macros, etc, in
11
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
- # run as spec files by default. This means that files in spec/support that end
13
- # in _spec.rb will both be required and run as specs, causing the specs to be
14
- # run twice. It is recommended that you do not name files matching this glob to
15
- # end with _spec.rb. You can configure this pattern with the --pattern
16
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
- #
18
- # The following line is provided for convenience purposes. It has the downside
19
- # of increasing the boot-up time by auto-requiring all files in the support
20
- # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
- # require only the support files necessary.
22
- #
23
- # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
24
-
25
- # Checks for pending migrations and applies them before tests are run.
26
- # If you are not using ActiveRecord, you can remove these lines.
27
- begin
28
- ActiveRecord::Migration.maintain_test_schema!
29
- rescue ActiveRecord::PendingMigrationError => e
30
- puts e.to_s.strip
31
- exit 1
32
- end
33
- RSpec.configure do |config|
34
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
36
-
37
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
38
- # examples within a transaction, remove the following line or assign false
39
- # instead of true.
40
- config.use_transactional_fixtures = true
41
-
42
- # RSpec Rails can automatically mix in different behaviours to your tests
43
- # based on their file location, for example enabling you to call `get` and
44
- # `post` in specs under `spec/controllers`.
45
- #
46
- # You can disable this behaviour by removing the line below, and instead
47
- # explicitly tag your specs with their type, e.g.:
48
- #
49
- # RSpec.describe UsersController, :type => :controller do
50
- # # ...
51
- # end
52
- #
53
- # The different available types are documented in the features, such as in
54
- # https://relishapp.com/rspec/rspec-rails/docs
55
- config.infer_spec_type_from_file_location!
56
-
57
- # Filter lines from Rails gems in backtraces.
58
- config.filter_rails_from_backtrace!
59
- # arbitrary gems may also be filtered via:
60
- # config.filter_gems_from_backtrace("gem name")
61
- end
@@ -1,97 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe 'Requesting Tree resources', :type => :request do
4
- before(:each) do
5
- user = User.create(name: 'Michel')
6
- tree = Tree.create(name: 'Lemon Tree', owner: user, cutter: user)
7
- end
8
-
9
- after(:each) do
10
- User.destroy_all
11
- Tree.destroy_all
12
- end
13
-
14
- before(:each) do
15
- allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
16
- allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
17
- allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
18
-
19
- allow_any_instance_of(ForestLiana::PermissionsChecker).to receive(:is_authorized?) { true }
20
- end
21
-
22
- headers = {
23
- 'Accept' => 'application/json',
24
- 'Content-Type' => 'application/json',
25
- 'Authorization' => 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxODQ5ODc4ODYzIiwiZGF0YSI6eyJpZCI6IjM4IiwidHlwZSI6InVzZXJzIiwiZGF0YSI6eyJlbWFpbCI6Im1pY2hhZWwua2Vsc29AdGhhdDcwLnNob3ciLCJmaXJzdF9uYW1lIjoiTWljaGFlbCIsImxhc3RfbmFtZSI6IktlbHNvIiwidGVhbXMiOiJPcGVyYXRpb25zIn0sInJlbGF0aW9uc2hpcHMiOnsicmVuZGVyaW5ncyI6eyJkYXRhIjpbeyJ0eXBlIjoicmVuZGVyaW5ncyIsImlkIjoxNn1dfX19fQ.U4Mxi0tq0Ce7y5FRXP47McNPRPhUx37LznQ5E3mJIp4'
26
- }
27
-
28
- describe 'index' do
29
- describe 'without any filter' do
30
- params = {
31
- fields: { 'Tree' => 'id,name' },
32
- page: { 'number' => '1', 'size' => '10' },
33
- searchExtended: '0',
34
- sort: '-id',
35
- timezone: 'Europe/Paris'
36
- }
37
-
38
- it 'should respond 200' do
39
- get '/forest/Tree', params, headers
40
- expect(response.status).to eq(200)
41
- end
42
-
43
- it 'should respond the tree data' do
44
- get '/forest/Tree', params, headers
45
- expect(JSON.parse(response.body)).to eq({
46
- "data" => [{
47
- "type" => "Tree",
48
- "id" => "1",
49
- "attributes" => {
50
- "id" => 1,
51
- "name" => "Lemon Tree"
52
- },
53
- "links" => {
54
- "self" => "/forest/tree/1"
55
- }
56
- }],
57
- "included" => []
58
- })
59
- end
60
- end
61
-
62
- describe 'with a filter on an association that is not a displayed column' do
63
- params = {
64
- fields: { 'Tree' => 'id,name' },
65
- filterType: 'and',
66
- filter: { 'owner:id' => '$present' },
67
- page: { 'number' => '1', 'size' => '10' },
68
- searchExtended: '0',
69
- sort: '-id',
70
- timezone: 'Europe/Paris'
71
- }
72
-
73
- it 'should respond 200' do
74
- get '/forest/Tree', params, headers
75
- expect(response.status).to eq(200)
76
- end
77
-
78
- it 'should respond the tree data' do
79
- get '/forest/Tree', params, headers
80
- expect(JSON.parse(response.body)).to eq({
81
- "data" => [{
82
- "type" => "Tree",
83
- "id" => "1",
84
- "attributes" => {
85
- "id" => 1,
86
- "name" => "Lemon Tree"
87
- },
88
- "links" => {
89
- "self" => "/forest/tree/1"
90
- }
91
- }],
92
- "included" => []
93
- })
94
- end
95
- end
96
- end
97
- end
@@ -1,172 +0,0 @@
1
- module ForestLiana
2
- describe ApimapSorter do
3
- describe 'apimap reordering' do
4
- context 'on a disordered apimap' do
5
- apimap = {
6
- 'meta': {
7
- 'orm_version': '4.34.9',
8
- 'liana_version': '1.5.24',
9
- 'database_type': 'postgresql',
10
- liana: 'forest-rails',
11
- },
12
- 'data': [{
13
- id: 'users',
14
- type: 'collections',
15
- attributes: {
16
- fields: [
17
- { field: 'id', type: 'Number' },
18
- { field: 'name', type: 'String' },
19
- { field: 'firstName', type: 'String' },
20
- { field: 'lastName', type: 'String' },
21
- { field: 'email', type: 'String' },
22
- { field: 'url', type: 'String' },
23
- { field: 'createdAt', type: 'Date' },
24
- { field: 'updatedAt', type: 'Date' },
25
- ],
26
- name: 'users',
27
- }
28
- }, {
29
- id: 'guests',
30
- type: 'collections',
31
- attributes: {
32
- fields: [
33
- { field: 'id', type: 'Number' },
34
- { field: 'email', type: 'String' },
35
- { field: 'createdAt', type: 'Date' },
36
- { field: 'updatedAt', type: 'Date' },
37
- ],
38
- name: 'guests',
39
- }
40
- }, {
41
- type: 'collections',
42
- id: 'animals',
43
- attributes: {
44
- fields: [
45
- { 'is-sortable': false, field: 'id', 'is-filterable': false, type: 'Number' },
46
- { type: 'Date', field: 'createdAt' },
47
- { field: 'updatedAt', type: 'Date' },
48
- ],
49
- name: 'animals',
50
- integration: 'close.io',
51
- 'is-virtual': true,
52
- }
53
- }],
54
- 'included': [{
55
- id: 'users.Women',
56
- type: 'segments',
57
- attributes: {
58
- name: 'Women'
59
- }
60
- }, {
61
- id: 'users.import',
62
- type: 'actions',
63
- links: {
64
- self: '/actions'
65
- },
66
- attributes: {
67
- name: 'import',
68
- fields: [{
69
- isRequired: true,
70
- type: 'Boolean',
71
- field: 'Save',
72
- description: 'save the import file if true.',
73
- defaultValue: 'true'
74
- }, {
75
- type: 'File',
76
- field: 'File'
77
- }],
78
- 'http-method': nil
79
- }
80
- }, {
81
- attributes: {
82
- name: 'Men'
83
- },
84
- id: 'users.Men',
85
- type: 'segments'
86
- }, {
87
- id: 'animals.ban',
88
- type: 'actions',
89
- links: {
90
- self: '/actions'
91
- },
92
- attributes: {
93
- name: 'import',
94
- global: true,
95
- download: nil,
96
- endpoint: nil,
97
- redirect: nil,
98
- 'http-method': nil
99
- }
100
- }]
101
- }
102
-
103
- apimap = ActiveSupport::JSON.encode(apimap)
104
- apimap = ActiveSupport::JSON.decode(apimap)
105
- apimap_sorted = ApimapSorter.new(apimap).perform
106
-
107
- it 'should sort the apimap sections' do
108
- expect(apimap_sorted.keys).to eq(['data', 'included', 'meta'])
109
- end
110
-
111
- it 'should sort the data collections' do
112
- expect(apimap_sorted['data'].map { |collection| collection['id'] }).to eq(
113
- ['animals', 'guests', 'users'])
114
- end
115
-
116
- it 'should sort the data collection values' do
117
- expect(apimap_sorted['data'][0].keys).to eq(['type', 'id', 'attributes'])
118
- expect(apimap_sorted['data'][1].keys).to eq(['type', 'id', 'attributes'])
119
- expect(apimap_sorted['data'][2].keys).to eq(['type', 'id', 'attributes'])
120
- end
121
-
122
- it 'should sort the data collections attributes values' do
123
- expect(apimap_sorted['data'][0]['attributes'].keys).to eq(['name', 'integration', 'is-virtual', 'fields'])
124
- expect(apimap_sorted['data'][1]['attributes'].keys).to eq(['name', 'fields'])
125
- expect(apimap_sorted['data'][2]['attributes'].keys).to eq(['name', 'fields'])
126
- end
127
-
128
- it 'should sort the data collections attributes fields by name' do
129
- expect(apimap_sorted['data'][0]['attributes']['fields'].map { |field| field['field'] }).to eq(['createdAt', 'id', 'updatedAt'])
130
- expect(apimap_sorted['data'][1]['attributes']['fields'].map { |field| field['field'] }).to eq(['createdAt', 'email', 'id', 'updatedAt'])
131
- expect(apimap_sorted['data'][2]['attributes']['fields'].map { |field| field['field'] }).to eq(['createdAt', 'email', 'firstName', 'id', 'lastName', 'name', 'updatedAt', 'url'])
132
- end
133
-
134
- it 'should sort the data collections attributes fields values' do
135
- expect(apimap_sorted['data'][0]['attributes']['fields'][1].keys).to eq(['field', 'type', 'is-filterable', 'is-sortable'])
136
- end
137
-
138
- it 'should sort the included actions and segments objects' do
139
- expect(apimap_sorted['included'].map { |object| object['id'] }).to eq(
140
- ['animals.ban', 'users.import', 'users.Men', 'users.Women'])
141
- end
142
-
143
- it 'should sort the included actions and segments objects values' do
144
- expect(apimap_sorted['included'][0].keys).to eq(['type', 'id', 'attributes', 'links'])
145
- expect(apimap_sorted['included'][1].keys).to eq(['type', 'id', 'attributes', 'links'])
146
- expect(apimap_sorted['included'][2].keys).to eq(['type', 'id', 'attributes'])
147
- expect(apimap_sorted['included'][3].keys).to eq(['type', 'id', 'attributes'])
148
- end
149
-
150
- it 'should sort the included actions and segments objects attributes values' do
151
- expect(apimap_sorted['included'][0]['attributes'].keys).to eq(['name', 'download', 'endpoint', 'global', 'http-method', 'redirect'])
152
- expect(apimap_sorted['included'][1]['attributes'].keys).to eq(['name', 'http-method', 'fields'])
153
- expect(apimap_sorted['included'][2]['attributes'].keys).to eq(['name'])
154
- expect(apimap_sorted['included'][3]['attributes'].keys).to eq(['name'])
155
- end
156
-
157
- it 'should sort the included action attributes fields by name' do
158
- expect(apimap_sorted['included'][1]['attributes']['fields'].map { |field| field['field'] }).to eq(['File', 'Save'])
159
- end
160
-
161
- it 'should sort the included action fields values' do
162
- expect(apimap_sorted['included'][1]['attributes']['fields'][1].keys).to eq(['field', 'type', 'defaultValue', 'description', 'isRequired'])
163
- end
164
-
165
- it 'should sort the meta values' do
166
- expect(apimap_sorted['meta'].keys).to eq(
167
- ['database_type', 'liana', 'liana_version', 'orm_version'])
168
- end
169
- end
170
- end
171
- end
172
- end
@@ -1,203 +0,0 @@
1
- module ForestLiana
2
- describe IpWhitelistChecker do
3
- describe 'Check is_ip_matches_rule function' do
4
- describe 'with IP "90.88.0.1" and "90.88.0.2"' do
5
- it 'should return false' do
6
- rule = {
7
- 'type' => 0,
8
- 'ip' => '90.88.0.1',
9
- }
10
-
11
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.2', rule)
12
-
13
- expect(is_matching).to eq(false)
14
- end
15
- end
16
-
17
- describe 'with IP "::1" and "aaaa"' do
18
- it 'should raise an "ArgumentError" exception with "Unknown IP Address aaaa" message' do
19
- rule = {
20
- 'type' => 0,
21
- 'ip' => '::1',
22
- }
23
-
24
- expect {
25
- IpWhitelistChecker.is_ip_matches_rule('aaaa', rule)
26
- }.to raise_error(ArgumentError, 'Unknown IP Address aaaa')
27
- end
28
- end
29
-
30
- describe 'with IP "90.88.0.1" and "::1"' do
31
- it 'should return false' do
32
- rule = {
33
- 'type' => 0,
34
- 'ip' => '90.88.0.1',
35
- }
36
-
37
- is_matching = IpWhitelistChecker.is_ip_matches_rule('::1', rule)
38
-
39
- expect(is_matching).to eq(false)
40
- end
41
- end
42
-
43
- describe 'with IP "::1" and "::1"' do
44
- it 'should return true' do
45
- rule = {
46
- 'type' => 0,
47
- 'ip' => '::1',
48
- }
49
-
50
- is_matching = IpWhitelistChecker.is_ip_matches_rule('::1', rule)
51
-
52
- expect(is_matching).to eq(true)
53
- end
54
- end
55
-
56
- describe 'with IP "90.88.0.1" and "90.88.0.1"' do
57
- it 'should return true' do
58
- rule = {
59
- 'type' => 0,
60
- 'ip' => '90.88.0.1',
61
- }
62
-
63
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.1', rule)
64
-
65
- expect(is_matching).to eq(true)
66
- end
67
- end
68
-
69
- describe 'with IP "90.88.0.0" and "90.88.0.0"' do
70
- it 'should return true' do
71
- rule = {
72
- 'type' => 0,
73
- 'ip' => '90.88.0.0',
74
- }
75
-
76
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.0', rule)
77
-
78
- expect(is_matching).to eq(true)
79
- end
80
- end
81
-
82
- describe 'with IP "127.0.0.1" and "::1"' do
83
- it 'should return true' do
84
- rule = {
85
- 'type' => 0,
86
- 'ip' => '127.0.0.1',
87
- }
88
-
89
- is_matching = IpWhitelistChecker.is_ip_matches_rule('::1', rule)
90
-
91
- expect(is_matching).to eq(true)
92
- end
93
- end
94
-
95
- describe 'with range "90.88.0.0 - 90.88.255.255' do
96
- rule = {
97
- 'type' => 1,
98
- 'ip_minimum' => '90.88.0.0',
99
- 'ip_maximum' => '90.88.255.255',
100
- }
101
-
102
- describe 'with IP "90.89.0.1"' do
103
- it 'should return false' do
104
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.89.0.1', rule)
105
-
106
- expect(is_matching).to eq(false)
107
- end
108
- end
109
-
110
- describe 'with IP "::ffff:90.89.0.1"' do
111
- it 'should return false' do
112
- is_matching = IpWhitelistChecker.is_ip_matches_rule('::ffff:90.89.0.1', rule)
113
-
114
- expect(is_matching).to eq(false)
115
- end
116
- end
117
-
118
- describe 'with IP "90.88.118.79"' do
119
- it 'should return false' do
120
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.118.79', rule)
121
-
122
- expect(is_matching).to eq(true)
123
- end
124
- end
125
- end
126
-
127
- describe 'with range "90.88.0.1 - 90.88.255.255" and IP "90.88.118.79"' do
128
- it 'should return true' do
129
- rule = {
130
- 'type' => 1,
131
- 'ip_minimum' => '90.88.0.1',
132
- 'ip_maximum' => '90.88.255.255',
133
- }
134
-
135
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.118.79', rule)
136
-
137
- expect(is_matching).to eq(true)
138
- end
139
- end
140
-
141
- describe 'with range "90.88.0.1 - 90.88.254.254" and IP "90.88.118.79"' do
142
- it 'should return true' do
143
- rule = {
144
- 'type' => 1,
145
- 'ip_minimum' => '90.88.0.1',
146
- 'ip_maximum' => '90.88.254.254',
147
- }
148
-
149
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.118.79', rule)
150
-
151
- expect(is_matching).to eq(true)
152
- end
153
- end
154
-
155
- describe 'with subnet "90.88.0.0/24"' do
156
- rule = {
157
- 'type' => 2,
158
- 'range' => '90.88.0.0/24',
159
- }
160
-
161
- describe 'with IP "90.88.0.1"' do
162
- it 'should return true' do
163
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.1', rule)
164
-
165
- expect(is_matching).to eq(true)
166
- end
167
- end
168
-
169
- describe 'with IP "90.88.0.0"' do
170
- it 'should return true' do
171
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.0', rule)
172
-
173
- expect(is_matching).to eq(true)
174
- end
175
- end
176
-
177
- describe 'with IP "90.88.0.254"' do
178
- it 'should return true' do
179
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.0.254', rule)
180
-
181
- expect(is_matching).to eq(true)
182
- end
183
- end
184
-
185
- describe 'with IP "90.88.1.1"' do
186
- it 'should return true' do
187
- is_matching = IpWhitelistChecker.is_ip_matches_rule('90.88.1.1', rule)
188
-
189
- expect(is_matching).to eq(false)
190
- end
191
- end
192
-
193
- describe 'with IP "::1"' do
194
- it 'should return true' do
195
- is_matching = IpWhitelistChecker.is_ip_matches_rule('::1', rule)
196
-
197
- expect(is_matching).to eq(false)
198
- end
199
- end
200
- end
201
- end
202
- end
203
- end