katgut 0.0.5 → 0.0.6
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 +4 -4
- data/app/models/katgut/rule.rb +16 -5
- data/db/migrate/20161219050212_change_type_of_destination_on_katgut_rules_to_text.rb +9 -0
- data/lib/katgut/version.rb +1 -1
- data/spec/dummy/db/schema.rb +2 -2
- data/spec/models/katgut/rule_spec.rb +6 -1
- data/spec/rails_helper.rb +2 -0
- metadata +31 -10
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -779
- data/spec/dummy/log/test.log +0 -9952
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 546779d691ef73b0f21d4298a4b7323663253069
|
4
|
+
data.tar.gz: 3e9434498c14261e1f2a077211311b9317a92552
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d534e9754180055ca41160cd81ad544f538d8afbdfb16deb0319f8bef4fd55263c567b105110fc2d721604dcdcd4da6f62362fe956897656b4f5de07fdda4942
|
7
|
+
data.tar.gz: 21d0e3fb67ff64de59eff501d4617cc5e29c9be042feaf82dd99c894cde2ac0d3f3dd1eaa0d124eb7bca5ecc174d021de308ab0db98f316ab4957654fe417e84
|
data/app/models/katgut/rule.rb
CHANGED
@@ -2,9 +2,10 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module Katgut
|
4
4
|
class Rule < ActiveRecord::Base
|
5
|
-
ALLOWED_SCHEMES
|
6
|
-
DEFAULT_SCHEME
|
7
|
-
MINIMUM_SOURCE_LENGTH
|
5
|
+
ALLOWED_SCHEMES = [:https, :http]
|
6
|
+
DEFAULT_SCHEME = :http
|
7
|
+
MINIMUM_SOURCE_LENGTH = 5
|
8
|
+
MAXIMUM_DESTINATION_LENGTH = 2083 # Limitation for IE / Edge
|
8
9
|
|
9
10
|
scope :active, -> { where(active: true) }
|
10
11
|
|
@@ -15,8 +16,8 @@ module Katgut
|
|
15
16
|
length: { in: MINIMUM_SOURCE_LENGTH .. 255 }
|
16
17
|
validates :destination,
|
17
18
|
presence: true,
|
18
|
-
|
19
|
-
|
19
|
+
length: { maximum: MAXIMUM_DESTINATION_LENGTH }
|
20
|
+
validate :ensure_destination_is_full_url_or_path
|
20
21
|
validate :ensure_destination_has_no_unallowed_scheme
|
21
22
|
|
22
23
|
after_initialize :set_random_source, if: -> { new_record? && source.nil? }
|
@@ -58,6 +59,16 @@ module Katgut
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
def ensure_destination_is_full_url_or_path
|
63
|
+
if destination =~ /\A#{URI::regexp}\z/
|
64
|
+
true
|
65
|
+
elsif "#{ALLOWED_SCHEMES.first}://example.com#{destination}" =~ /\A#{URI::regexp}\z/
|
66
|
+
true
|
67
|
+
else
|
68
|
+
errors.add(:destination, "is neither in full URL format nor path format")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
61
72
|
def set_random_source
|
62
73
|
self.source = SecureRandom.urlsafe_base64(6)
|
63
74
|
end
|
data/lib/katgut/version.rb
CHANGED
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,11 +11,11 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20161219050212) do
|
15
15
|
|
16
16
|
create_table "katgut_rules", force: :cascade do |t|
|
17
17
|
t.string "source", null: false
|
18
|
-
t.
|
18
|
+
t.text "destination", null: false
|
19
19
|
t.boolean "active", default: false, null: false
|
20
20
|
t.datetime "created_at", null: false
|
21
21
|
t.datetime "updated_at", null: false
|
@@ -28,7 +28,7 @@ RSpec.describe Katgut::Rule, type: :model do
|
|
28
28
|
expect(rule).not_to be_valid
|
29
29
|
end
|
30
30
|
|
31
|
-
it 'doesn\'t allow
|
31
|
+
it 'doesn\'t allow invalid characters in destination col' do
|
32
32
|
rule.destination = '/test/<>'
|
33
33
|
expect(rule).not_to be_valid
|
34
34
|
end
|
@@ -37,6 +37,11 @@ RSpec.describe Katgut::Rule, type: :model do
|
|
37
37
|
rule.destination = 'ftp://ftp.naist.jp'
|
38
38
|
expect(rule).not_to be_valid
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'doesn\'t allow destination url longer than 2083 characters' do
|
42
|
+
rule.destination += 'a' * (2083 - rule.destination.length) + 'X'
|
43
|
+
expect(rule).not_to be_valid
|
44
|
+
end
|
40
45
|
end
|
41
46
|
|
42
47
|
describe "#regular_destination" do
|
data/spec/rails_helper.rb
CHANGED
@@ -5,6 +5,8 @@ require File.expand_path('../dummy/config/environment', __FILE__)
|
|
5
5
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
6
6
|
require 'spec_helper'
|
7
7
|
require 'rspec/rails'
|
8
|
+
require 'pry'
|
9
|
+
require 'awesome_print'
|
8
10
|
|
9
11
|
ActiveRecord::Migration.maintain_test_schema!
|
10
12
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katgut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HAMADA Kazuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -86,6 +86,34 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '1.5'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pry-byebug
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.4'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.4'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: awesome_print
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.7'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.7'
|
89
117
|
description: It Sutures a URL onto another with a redirection path
|
90
118
|
email:
|
91
119
|
- hamada.kazuki.mum@gmail.com
|
@@ -105,6 +133,7 @@ files:
|
|
105
133
|
- app/views/layouts/katgut/application.html.erb
|
106
134
|
- config/routes.rb
|
107
135
|
- db/migrate/20160704065128_create_katgut_rules.rb
|
136
|
+
- db/migrate/20161219050212_change_type_of_destination_on_katgut_rules_to_text.rb
|
108
137
|
- lib/generators/katgut/initializer/USAGE
|
109
138
|
- lib/generators/katgut/initializer/initializer_generator.rb
|
110
139
|
- lib/generators/katgut/initializer/templates/initializer.rb
|
@@ -145,11 +174,7 @@ files:
|
|
145
174
|
- spec/dummy/config/locales/en.yml
|
146
175
|
- spec/dummy/config/routes.rb
|
147
176
|
- spec/dummy/config/secrets.yml
|
148
|
-
- spec/dummy/db/development.sqlite3
|
149
177
|
- spec/dummy/db/schema.rb
|
150
|
-
- spec/dummy/db/test.sqlite3
|
151
|
-
- spec/dummy/log/development.log
|
152
|
-
- spec/dummy/log/test.log
|
153
178
|
- spec/dummy/public/404.html
|
154
179
|
- spec/dummy/public/422.html
|
155
180
|
- spec/dummy/public/500.html
|
@@ -217,11 +242,7 @@ test_files:
|
|
217
242
|
- spec/dummy/config/routes.rb
|
218
243
|
- spec/dummy/config/secrets.yml
|
219
244
|
- spec/dummy/config.ru
|
220
|
-
- spec/dummy/db/development.sqlite3
|
221
245
|
- spec/dummy/db/schema.rb
|
222
|
-
- spec/dummy/db/test.sqlite3
|
223
|
-
- spec/dummy/log/development.log
|
224
|
-
- spec/dummy/log/test.log
|
225
246
|
- spec/dummy/public/404.html
|
226
247
|
- spec/dummy/public/422.html
|
227
248
|
- spec/dummy/public/500.html
|
Binary file
|
data/spec/dummy/db/test.sqlite3
DELETED
Binary file
|