hash_validator 2.0.0 → 2.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 +4 -4
- data/.github/workflows/ruby.yml +6 -1
- data/.rubocop.yml +340 -0
- data/Gemfile +3 -1
- data/README.md +2 -1
- data/Rakefile +6 -4
- data/hash_validator.gemspec +11 -5
- data/lib/hash_validator/base.rb +2 -0
- data/lib/hash_validator/configuration.rb +5 -3
- data/lib/hash_validator/validations/many.rb +2 -0
- data/lib/hash_validator/validations/multiple.rb +2 -0
- data/lib/hash_validator/validations/optional.rb +2 -0
- data/lib/hash_validator/validations.rb +5 -3
- data/lib/hash_validator/validators/alpha_validator.rb +5 -3
- data/lib/hash_validator/validators/alphanumeric_validator.rb +5 -3
- data/lib/hash_validator/validators/array_validator.rb +44 -48
- data/lib/hash_validator/validators/base.rb +6 -4
- data/lib/hash_validator/validators/boolean_validator.rb +3 -1
- data/lib/hash_validator/validators/class_validator.rb +3 -1
- data/lib/hash_validator/validators/digits_validator.rb +5 -3
- data/lib/hash_validator/validators/dynamic_func_validator.rb +8 -8
- data/lib/hash_validator/validators/dynamic_pattern_validator.rb +5 -3
- data/lib/hash_validator/validators/email_validator.rb +4 -2
- data/lib/hash_validator/validators/enumerable_validator.rb +4 -2
- data/lib/hash_validator/validators/hash_validator.rb +5 -3
- data/lib/hash_validator/validators/hex_color_validator.rb +5 -3
- data/lib/hash_validator/validators/ip_validator.rb +6 -4
- data/lib/hash_validator/validators/ipv4_validator.rb +5 -3
- data/lib/hash_validator/validators/ipv6_validator.rb +6 -4
- data/lib/hash_validator/validators/json_validator.rb +6 -4
- data/lib/hash_validator/validators/lambda_validator.rb +4 -2
- data/lib/hash_validator/validators/many_validator.rb +3 -1
- data/lib/hash_validator/validators/multiple_validator.rb +4 -2
- data/lib/hash_validator/validators/optional_validator.rb +3 -1
- data/lib/hash_validator/validators/presence_validator.rb +4 -2
- data/lib/hash_validator/validators/regex_validator.rb +4 -2
- data/lib/hash_validator/validators/simple_type_validators.rb +3 -1
- data/lib/hash_validator/validators/simple_validator.rb +2 -0
- data/lib/hash_validator/validators/url_validator.rb +6 -4
- data/lib/hash_validator/validators.rb +35 -33
- data/lib/hash_validator/version.rb +3 -1
- data/lib/hash_validator.rb +7 -5
- data/spec/configuration_spec.rb +76 -74
- data/spec/hash_validator_spec.rb +132 -113
- data/spec/hash_validator_spec_helper.rb +2 -0
- data/spec/spec_helper.rb +14 -4
- data/spec/validators/alpha_validator_spec.rb +43 -41
- data/spec/validators/alphanumeric_validator_spec.rb +44 -42
- data/spec/validators/array_spec.rb +102 -47
- data/spec/validators/base_spec.rb +25 -10
- data/spec/validators/boolean_spec.rb +15 -13
- data/spec/validators/class_spec.rb +20 -18
- data/spec/validators/digits_validator_spec.rb +46 -44
- data/spec/validators/dynamic_func_validator_spec.rb +90 -88
- data/spec/validators/dynamic_pattern_validator_spec.rb +65 -63
- data/spec/validators/email_spec.rb +15 -13
- data/spec/validators/hash_validator_spec.rb +39 -37
- data/spec/validators/hex_color_validator_spec.rb +49 -47
- data/spec/validators/in_enumerable_spec.rb +32 -30
- data/spec/validators/ip_validator_spec.rb +46 -44
- data/spec/validators/ipv4_validator_spec.rb +45 -43
- data/spec/validators/ipv6_validator_spec.rb +44 -42
- data/spec/validators/json_validator_spec.rb +38 -36
- data/spec/validators/lambda_spec.rb +20 -18
- data/spec/validators/many_spec.rb +25 -23
- data/spec/validators/multiple_spec.rb +13 -11
- data/spec/validators/optional_spec.rb +22 -20
- data/spec/validators/presence_spec.rb +16 -14
- data/spec/validators/regexp_spec.rb +14 -12
- data/spec/validators/simple_spec.rb +17 -15
- data/spec/validators/simple_types_spec.rb +21 -19
- data/spec/validators/url_validator_spec.rb +34 -32
- data/spec/validators/user_defined_spec.rb +29 -27
- metadata +59 -2
@@ -1,67 +1,69 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Enumerable validator" do
|
6
|
+
describe "Accepting Enumerables in validations" do
|
7
|
+
it "should accept an empty array" do
|
6
8
|
validate({}, { foo: [] })
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
10
|
-
validate({}, { foo: [
|
11
|
+
it "should accept an array" do
|
12
|
+
validate({}, { foo: [ "apple", "banana", "carrot" ] })
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
14
|
-
validate({}, { foo: { apple:
|
15
|
+
it "should accept a hash" do
|
16
|
+
validate({}, { foo: { apple: "apple", banana: "banana", carrot: "cattot" } })
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
describe
|
19
|
-
describe
|
20
|
-
let(:validations) {{ fruit: [
|
20
|
+
describe "#validate" do
|
21
|
+
describe "Simple Array" do
|
22
|
+
let(:validations) { { fruit: [ "apple", "banana", "carrot" ] } }
|
21
23
|
|
22
|
-
it
|
23
|
-
expect(validate({ fruit:
|
24
|
+
it "should validate true if the value is present" do
|
25
|
+
expect(validate({ fruit: "apple" }, validations).valid?).to eq true
|
24
26
|
end
|
25
27
|
|
26
|
-
it
|
27
|
-
expect(validate({ fruit:
|
28
|
+
it "should validate false if the value is not present" do
|
29
|
+
expect(validate({ fruit: "pear" }, validations).valid?).to eq false
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
31
|
-
expect(validate({ something:
|
32
|
+
it "should validate false if the key is not present" do
|
33
|
+
expect(validate({ something: "apple" }, validations).valid?).to eq false
|
32
34
|
end
|
33
35
|
|
34
|
-
it
|
35
|
-
expect(validate({ fruit:
|
36
|
+
it "should provide an appropriate error message is the value is not present" do
|
37
|
+
expect(validate({ fruit: "pear" }, validations).errors).to eq({ fruit: "value from list required" })
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
describe
|
40
|
-
let(:validations) {{ number: 1..10 }}
|
41
|
+
describe "Range" do
|
42
|
+
let(:validations) { { number: 1..10 } }
|
41
43
|
|
42
|
-
it
|
44
|
+
it "should validate true if the value is present" do
|
43
45
|
expect(validate({ number: 5 }, validations).valid?).to eq true
|
44
46
|
end
|
45
|
-
it
|
47
|
+
it "should validate false if the value is not present" do
|
46
48
|
expect(validate({ number: 15 }, validations).valid?).to eq false
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
describe
|
51
|
-
let(:validations) {{ number: 1..Float::INFINITY }}
|
52
|
+
describe "Infinite Range" do
|
53
|
+
let(:validations) { { number: 1..Float::INFINITY } }
|
52
54
|
|
53
|
-
it
|
55
|
+
it "should validate true if the value is present" do
|
54
56
|
expect(validate({ number: 5 }, validations).valid?).to eq true
|
55
57
|
end
|
56
|
-
it
|
58
|
+
it "should validate false if the value is not present" do
|
57
59
|
expect(validate({ number: -5 }, validations).valid?).to eq false
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
describe
|
62
|
-
let(:validations) {{ fruit: [ nil, :apple, :banana ] }}
|
63
|
+
describe "nil values" do
|
64
|
+
let(:validations) { { fruit: [ nil, :apple, :banana ] } }
|
63
65
|
|
64
|
-
it
|
66
|
+
it "should validate true if a nil value is present" do
|
65
67
|
expect(validate({ fruit: nil }, validations).valid?).to eq true
|
66
68
|
end
|
67
69
|
end
|
@@ -1,105 +1,107 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
describe HashValidator::Validator::IpValidator do
|
4
6
|
let(:validator) { HashValidator::Validator::IpValidator.new }
|
5
7
|
|
6
|
-
context
|
7
|
-
it
|
8
|
+
context "valid IP addresses" do
|
9
|
+
it "validates IPv4 addresses" do
|
8
10
|
errors = {}
|
9
|
-
validator.validate(
|
11
|
+
validator.validate("key", "192.168.1.1", {}, errors)
|
10
12
|
expect(errors).to be_empty
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
15
|
+
it "validates IPv4 localhost" do
|
14
16
|
errors = {}
|
15
|
-
validator.validate(
|
17
|
+
validator.validate("key", "127.0.0.1", {}, errors)
|
16
18
|
expect(errors).to be_empty
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
21
|
+
it "validates IPv4 zero address" do
|
20
22
|
errors = {}
|
21
|
-
validator.validate(
|
23
|
+
validator.validate("key", "0.0.0.0", {}, errors)
|
22
24
|
expect(errors).to be_empty
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it "validates IPv4 broadcast address" do
|
26
28
|
errors = {}
|
27
|
-
validator.validate(
|
29
|
+
validator.validate("key", "255.255.255.255", {}, errors)
|
28
30
|
expect(errors).to be_empty
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
33
|
+
it "validates IPv6 addresses" do
|
32
34
|
errors = {}
|
33
|
-
validator.validate(
|
35
|
+
validator.validate("key", "2001:db8:85a3::8a2e:370:7334", {}, errors)
|
34
36
|
expect(errors).to be_empty
|
35
37
|
end
|
36
38
|
|
37
|
-
it
|
39
|
+
it "validates IPv6 localhost" do
|
38
40
|
errors = {}
|
39
|
-
validator.validate(
|
41
|
+
validator.validate("key", "::1", {}, errors)
|
40
42
|
expect(errors).to be_empty
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
45
|
+
it "validates IPv6 zero address" do
|
44
46
|
errors = {}
|
45
|
-
validator.validate(
|
47
|
+
validator.validate("key", "::", {}, errors)
|
46
48
|
expect(errors).to be_empty
|
47
49
|
end
|
48
50
|
|
49
|
-
it
|
51
|
+
it "validates IPv4-mapped IPv6 addresses" do
|
50
52
|
errors = {}
|
51
|
-
validator.validate(
|
53
|
+
validator.validate("key", "::ffff:192.168.1.1", {}, errors)
|
52
54
|
expect(errors).to be_empty
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
context
|
57
|
-
it
|
58
|
+
context "invalid IP addresses" do
|
59
|
+
it "rejects non-string values" do
|
58
60
|
errors = {}
|
59
|
-
validator.validate(
|
60
|
-
expect(errors[
|
61
|
+
validator.validate("key", 123, {}, errors)
|
62
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
61
63
|
end
|
62
64
|
|
63
|
-
it
|
65
|
+
it "rejects nil values" do
|
64
66
|
errors = {}
|
65
|
-
validator.validate(
|
66
|
-
expect(errors[
|
67
|
+
validator.validate("key", nil, {}, errors)
|
68
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
67
69
|
end
|
68
70
|
|
69
|
-
it
|
71
|
+
it "rejects malformed IPv4 addresses" do
|
70
72
|
errors = {}
|
71
|
-
validator.validate(
|
72
|
-
expect(errors[
|
73
|
+
validator.validate("key", "256.1.1.1", {}, errors)
|
74
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
73
75
|
end
|
74
76
|
|
75
|
-
it
|
77
|
+
it "rejects malformed IPv6 addresses" do
|
76
78
|
errors = {}
|
77
|
-
validator.validate(
|
78
|
-
expect(errors[
|
79
|
+
validator.validate("key", "2001:db8:85a3::8a2e::7334", {}, errors)
|
80
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
83
|
+
it "rejects non-IP strings" do
|
82
84
|
errors = {}
|
83
|
-
validator.validate(
|
84
|
-
expect(errors[
|
85
|
+
validator.validate("key", "not an ip", {}, errors)
|
86
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
85
87
|
end
|
86
88
|
|
87
|
-
it
|
89
|
+
it "rejects empty strings" do
|
88
90
|
errors = {}
|
89
|
-
validator.validate(
|
90
|
-
expect(errors[
|
91
|
+
validator.validate("key", "", {}, errors)
|
92
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
91
93
|
end
|
92
94
|
|
93
|
-
it
|
95
|
+
it "rejects hostnames" do
|
94
96
|
errors = {}
|
95
|
-
validator.validate(
|
96
|
-
expect(errors[
|
97
|
+
validator.validate("key", "example.com", {}, errors)
|
98
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
97
99
|
end
|
98
100
|
|
99
|
-
it
|
101
|
+
it "rejects URLs" do
|
100
102
|
errors = {}
|
101
|
-
validator.validate(
|
102
|
-
expect(errors[
|
103
|
+
validator.validate("key", "http://192.168.1.1", {}, errors)
|
104
|
+
expect(errors["key"]).to eq("is not a valid IP address")
|
103
105
|
end
|
104
106
|
end
|
105
|
-
end
|
107
|
+
end
|
@@ -1,99 +1,101 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
describe HashValidator::Validator::Ipv4Validator do
|
4
6
|
let(:validator) { HashValidator::Validator::Ipv4Validator.new }
|
5
7
|
|
6
|
-
context
|
7
|
-
it
|
8
|
+
context "valid IPv4 addresses" do
|
9
|
+
it "validates standard IPv4 addresses" do
|
8
10
|
errors = {}
|
9
|
-
validator.validate(
|
11
|
+
validator.validate("key", "192.168.1.1", {}, errors)
|
10
12
|
expect(errors).to be_empty
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
15
|
+
it "validates localhost" do
|
14
16
|
errors = {}
|
15
|
-
validator.validate(
|
17
|
+
validator.validate("key", "127.0.0.1", {}, errors)
|
16
18
|
expect(errors).to be_empty
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
21
|
+
it "validates zero address" do
|
20
22
|
errors = {}
|
21
|
-
validator.validate(
|
23
|
+
validator.validate("key", "0.0.0.0", {}, errors)
|
22
24
|
expect(errors).to be_empty
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it "validates broadcast address" do
|
26
28
|
errors = {}
|
27
|
-
validator.validate(
|
29
|
+
validator.validate("key", "255.255.255.255", {}, errors)
|
28
30
|
expect(errors).to be_empty
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
33
|
+
it "validates private network addresses" do
|
32
34
|
errors = {}
|
33
|
-
validator.validate(
|
35
|
+
validator.validate("key", "10.0.0.1", {}, errors)
|
34
36
|
expect(errors).to be_empty
|
35
37
|
end
|
36
38
|
|
37
|
-
it
|
39
|
+
it "validates Class B private addresses" do
|
38
40
|
errors = {}
|
39
|
-
validator.validate(
|
41
|
+
validator.validate("key", "172.16.0.1", {}, errors)
|
40
42
|
expect(errors).to be_empty
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
context
|
45
|
-
it
|
46
|
+
context "invalid IPv4 addresses" do
|
47
|
+
it "rejects non-string values" do
|
46
48
|
errors = {}
|
47
|
-
validator.validate(
|
48
|
-
expect(errors[
|
49
|
+
validator.validate("key", 123, {}, errors)
|
50
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
49
51
|
end
|
50
52
|
|
51
|
-
it
|
53
|
+
it "rejects nil values" do
|
52
54
|
errors = {}
|
53
|
-
validator.validate(
|
54
|
-
expect(errors[
|
55
|
+
validator.validate("key", nil, {}, errors)
|
56
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
55
57
|
end
|
56
58
|
|
57
|
-
it
|
59
|
+
it "rejects octets over 255" do
|
58
60
|
errors = {}
|
59
|
-
validator.validate(
|
60
|
-
expect(errors[
|
61
|
+
validator.validate("key", "256.1.1.1", {}, errors)
|
62
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
61
63
|
end
|
62
64
|
|
63
|
-
it
|
65
|
+
it "rejects too few octets" do
|
64
66
|
errors = {}
|
65
|
-
validator.validate(
|
66
|
-
expect(errors[
|
67
|
+
validator.validate("key", "192.168.1", {}, errors)
|
68
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
67
69
|
end
|
68
70
|
|
69
|
-
it
|
71
|
+
it "rejects too many octets" do
|
70
72
|
errors = {}
|
71
|
-
validator.validate(
|
72
|
-
expect(errors[
|
73
|
+
validator.validate("key", "192.168.1.1.1", {}, errors)
|
74
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
73
75
|
end
|
74
76
|
|
75
|
-
it
|
77
|
+
it "rejects IPv6 addresses" do
|
76
78
|
errors = {}
|
77
|
-
validator.validate(
|
78
|
-
expect(errors[
|
79
|
+
validator.validate("key", "2001:db8::1", {}, errors)
|
80
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
83
|
+
it "rejects malformed addresses" do
|
82
84
|
errors = {}
|
83
|
-
validator.validate(
|
84
|
-
expect(errors[
|
85
|
+
validator.validate("key", "192.168.1.", {}, errors)
|
86
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
85
87
|
end
|
86
88
|
|
87
|
-
it
|
89
|
+
it "rejects empty strings" do
|
88
90
|
errors = {}
|
89
|
-
validator.validate(
|
90
|
-
expect(errors[
|
91
|
+
validator.validate("key", "", {}, errors)
|
92
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
91
93
|
end
|
92
94
|
|
93
|
-
it
|
95
|
+
it "rejects non-numeric octets" do
|
94
96
|
errors = {}
|
95
|
-
validator.validate(
|
96
|
-
expect(errors[
|
97
|
+
validator.validate("key", "192.168.a.1", {}, errors)
|
98
|
+
expect(errors["key"]).to eq("is not a valid IPv4 address")
|
97
99
|
end
|
98
100
|
end
|
99
|
-
end
|
101
|
+
end
|
@@ -1,99 +1,101 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
describe HashValidator::Validator::Ipv6Validator do
|
4
6
|
let(:validator) { HashValidator::Validator::Ipv6Validator.new }
|
5
7
|
|
6
|
-
context
|
7
|
-
it
|
8
|
+
context "valid IPv6 addresses" do
|
9
|
+
it "validates full IPv6 addresses" do
|
8
10
|
errors = {}
|
9
|
-
validator.validate(
|
11
|
+
validator.validate("key", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", {}, errors)
|
10
12
|
expect(errors).to be_empty
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
15
|
+
it "validates compressed IPv6 addresses" do
|
14
16
|
errors = {}
|
15
|
-
validator.validate(
|
17
|
+
validator.validate("key", "2001:db8:85a3::8a2e:370:7334", {}, errors)
|
16
18
|
expect(errors).to be_empty
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
21
|
+
it "validates IPv6 localhost" do
|
20
22
|
errors = {}
|
21
|
-
validator.validate(
|
23
|
+
validator.validate("key", "::1", {}, errors)
|
22
24
|
expect(errors).to be_empty
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it "validates IPv6 zero address" do
|
26
28
|
errors = {}
|
27
|
-
validator.validate(
|
29
|
+
validator.validate("key", "::", {}, errors)
|
28
30
|
expect(errors).to be_empty
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
33
|
+
it "validates IPv6 with leading zeros" do
|
32
34
|
errors = {}
|
33
|
-
validator.validate(
|
35
|
+
validator.validate("key", "2001:0db8::0001", {}, errors)
|
34
36
|
expect(errors).to be_empty
|
35
37
|
end
|
36
38
|
|
37
|
-
it
|
39
|
+
it "validates IPv6 with mixed case" do
|
38
40
|
errors = {}
|
39
|
-
validator.validate(
|
41
|
+
validator.validate("key", "2001:DB8::1", {}, errors)
|
40
42
|
expect(errors).to be_empty
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
45
|
+
it "validates IPv4-mapped IPv6 addresses" do
|
44
46
|
errors = {}
|
45
|
-
validator.validate(
|
47
|
+
validator.validate("key", "::ffff:192.168.1.1", {}, errors)
|
46
48
|
expect(errors).to be_empty
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
context
|
51
|
-
it
|
52
|
+
context "invalid IPv6 addresses" do
|
53
|
+
it "rejects non-string values" do
|
52
54
|
errors = {}
|
53
|
-
validator.validate(
|
54
|
-
expect(errors[
|
55
|
+
validator.validate("key", 123, {}, errors)
|
56
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
55
57
|
end
|
56
58
|
|
57
|
-
it
|
59
|
+
it "rejects nil values" do
|
58
60
|
errors = {}
|
59
|
-
validator.validate(
|
60
|
-
expect(errors[
|
61
|
+
validator.validate("key", nil, {}, errors)
|
62
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
61
63
|
end
|
62
64
|
|
63
|
-
it
|
65
|
+
it "rejects IPv4 addresses" do
|
64
66
|
errors = {}
|
65
|
-
validator.validate(
|
66
|
-
expect(errors[
|
67
|
+
validator.validate("key", "192.168.1.1", {}, errors)
|
68
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
67
69
|
end
|
68
70
|
|
69
|
-
it
|
71
|
+
it "rejects malformed IPv6 addresses" do
|
70
72
|
errors = {}
|
71
|
-
validator.validate(
|
72
|
-
expect(errors[
|
73
|
+
validator.validate("key", "2001:db8:85a3::8a2e::7334", {}, errors)
|
74
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
73
75
|
end
|
74
76
|
|
75
|
-
it
|
77
|
+
it "rejects too many groups" do
|
76
78
|
errors = {}
|
77
|
-
validator.validate(
|
78
|
-
expect(errors[
|
79
|
+
validator.validate("key", "2001:0db8:85a3:0000:0000:8a2e:0370:7334:extra", {}, errors)
|
80
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
83
|
+
it "rejects invalid characters" do
|
82
84
|
errors = {}
|
83
|
-
validator.validate(
|
84
|
-
expect(errors[
|
85
|
+
validator.validate("key", "2001:db8:85a3::8a2g:370:7334", {}, errors)
|
86
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
85
87
|
end
|
86
88
|
|
87
|
-
it
|
89
|
+
it "rejects empty strings" do
|
88
90
|
errors = {}
|
89
|
-
validator.validate(
|
90
|
-
expect(errors[
|
91
|
+
validator.validate("key", "", {}, errors)
|
92
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
91
93
|
end
|
92
94
|
|
93
|
-
it
|
95
|
+
it "rejects incomplete addresses" do
|
94
96
|
errors = {}
|
95
|
-
validator.validate(
|
96
|
-
expect(errors[
|
97
|
+
validator.validate("key", "2001:db8:", {}, errors)
|
98
|
+
expect(errors["key"]).to eq("is not a valid IPv6 address")
|
97
99
|
end
|
98
100
|
end
|
99
|
-
end
|
101
|
+
end
|