validocno 0.2.4 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/validocno/validator.rb +7 -30
- data/lib/validocno/version.rb +1 -1
- data/spec/fixtures/post_response.html +5 -40
- data/spec/validator_spec.rb +34 -37
- data/spec/validocno_spec.rb +0 -3
- data/validocno.gemspec +2 -2
- metadata +5 -7
- data/spec/fixtures/get_response.html +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c701049917e6c1837b7287afb9dd1785e456abf8806bc67bb652e21ba216c274
|
4
|
+
data.tar.gz: 618f7406a626e04d14fc488f932981578e7ad9958d2bafcab1c1ec628c74b13e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df99b223597f87c56825aec964c84638f319c2e6636985529fbe86d017b86ecc1610e896b1f86188530f254947cc5781b67eeeac8e7097a5b5c5e5934eac92cf
|
7
|
+
data.tar.gz: 9e987fe47109b3a743188b1962d5422d354d27d0f0624cf5f4e8841a654fc06f66c03e163fddfcf24e18d7aaac496234c60467bbf3337df2b686f790dc4df97e
|
data/lib/validocno/validator.rb
CHANGED
@@ -1,57 +1,34 @@
|
|
1
1
|
module Validocno
|
2
2
|
class Validator
|
3
|
-
# Set strings to UTF-8 mode
|
4
|
-
$KCODE = 'UTF-8'
|
5
3
|
|
6
|
-
CONTROL_URI =
|
4
|
+
CONTROL_URI = "https://www2.politsei.ee/qr/".freeze
|
7
5
|
|
8
6
|
def initialize(doc_number)
|
9
7
|
@doc_number = doc_number
|
10
|
-
@csrf_token = csrf_token
|
11
|
-
end
|
12
|
-
|
13
|
-
def csrf_token
|
14
|
-
response = RestClient.get(CONTROL_URI)
|
15
|
-
check_response(response)
|
16
|
-
|
17
|
-
document = Nokogiri::HTML(response)
|
18
|
-
|
19
|
-
node = document.at_css('form[name="reqForm"] input[name="csrf"]')
|
20
|
-
|
21
|
-
if node.nil? || node['value'].nil?
|
22
|
-
fail StandardError, 'CSRF token was not found on page'
|
23
|
-
else
|
24
|
-
node['value']
|
25
|
-
end
|
26
8
|
end
|
27
9
|
|
28
10
|
def response_string
|
29
|
-
|
30
|
-
:cmd => 'request',
|
31
|
-
:csrf => @csrf_token,
|
32
|
-
:docNumber => @doc_number
|
33
|
-
}
|
34
|
-
|
35
|
-
response = RestClient.post(CONTROL_URI, options)
|
11
|
+
response = RestClient.get(CONTROL_URI, :params => { :qr => @doc_number })
|
36
12
|
check_response(response)
|
37
13
|
|
38
14
|
document = Nokogiri::HTML(response)
|
39
15
|
|
40
|
-
node = document.at_css(
|
16
|
+
node = document.at_css(".qrWidgetDocumentCheckResult")
|
41
17
|
|
42
18
|
if node.nil? || node.children.empty?
|
43
19
|
fail StandardError, 'Cannot parse document status string.'
|
44
20
|
else
|
45
|
-
node.children.
|
21
|
+
node.children.at_css("div").text.strip
|
46
22
|
end
|
47
23
|
end
|
48
24
|
|
49
25
|
def validate
|
50
|
-
|
26
|
+
response_string_result = response_string
|
27
|
+
is_valid = response_string_result == response_strings[:valid]
|
51
28
|
|
52
29
|
{
|
53
30
|
:valid => is_valid,
|
54
|
-
:message =>
|
31
|
+
:message => response_string_result
|
55
32
|
}
|
56
33
|
end
|
57
34
|
|
data/lib/validocno/version.rb
CHANGED
@@ -1,41 +1,6 @@
|
|
1
1
|
<div id="content1left" class="content" style="min-height: 500px;">
|
2
|
-
<
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<br>
|
8
|
-
<form name="reqForm" method="post" action="">
|
9
|
-
<input type="hidden" name="cmd" value="request">
|
10
|
-
<input type="hidden" name="csrf" value="iiGifsNdIY/OVVbEXnh3hMLtJgXsKomOlWKClE2DozCAo/KdBk0N7g==">
|
11
|
-
<table class="form">
|
12
|
-
<tbody>
|
13
|
-
<tr>
|
14
|
-
<td class="label">Dokumendi number:</td>
|
15
|
-
<td>
|
16
|
-
<input class="basicInputText" type="text"
|
17
|
-
name="docNumber" size="20" maxlength="20" value="">
|
18
|
-
</td>
|
19
|
-
</tr>
|
20
|
-
<tr>
|
21
|
-
<td colspan="2">
|
22
|
-
</td>
|
23
|
-
</tr>
|
24
|
-
<tr>
|
25
|
-
<td colspan="2">
|
26
|
-
</td>
|
27
|
-
</tr>
|
28
|
-
<tr>
|
29
|
-
<td>
|
30
|
-
</td>
|
31
|
-
<td>
|
32
|
-
<input class="basicInputButton button100px" type="submit"
|
33
|
-
name="subButton" value="Esita päring">
|
34
|
-
</td>
|
35
|
-
</tr>
|
36
|
-
</tbody>
|
37
|
-
</table>
|
38
|
-
</form>
|
39
|
-
<br>
|
40
|
-
Dokument A1234567 on kehtiv.
|
41
|
-
</div>
|
2
|
+
<div class="qrWidgetDocumentCheckResult">
|
3
|
+
<div class="qrDocumentValid">Dokument A1234567 on kehtiv.</div>
|
4
|
+
<div class="qrDocumentValid">The document A1234567 is valid.</div>
|
5
|
+
</div>
|
6
|
+
</div>
|
data/spec/validator_spec.rb
CHANGED
@@ -1,43 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Validocno::Validator do
|
4
|
-
let(:doc_number) {
|
4
|
+
let(:doc_number) { "A1234567" }
|
5
5
|
let(:validator) { Validocno::Validator.new(doc_number) }
|
6
|
-
let(:
|
7
|
-
body = File.new('spec/fixtures/get_response.html').read
|
8
|
-
Nokogiri::HTML(body)
|
9
|
-
end
|
6
|
+
let(:invalid_post_validator) { Validocno::Validator.new("00000000") }
|
10
7
|
|
11
8
|
let(:valid_nr_response) do
|
12
9
|
body = File.new('spec/fixtures/post_response.html').read
|
13
|
-
|
10
|
+
{ :body => body, :document_number => doc_number }
|
14
11
|
end
|
15
12
|
|
16
13
|
let(:expired_nr_response) do
|
17
14
|
body = File.new('spec/fixtures/post_response.html').read
|
18
|
-
body = body.gsub(
|
19
|
-
body = body.gsub(
|
20
|
-
|
15
|
+
body = body.gsub(doc_number, "A0111856")
|
16
|
+
body = body.gsub("kehtiv", "kehtetu")
|
17
|
+
{ :body => body, :document_number => "A0111856" }
|
21
18
|
end
|
22
19
|
|
23
20
|
let(:invalid_nr_response) do
|
24
21
|
body = File.new('spec/fixtures/post_response.html').read
|
25
|
-
body = body.gsub(
|
22
|
+
body = body.gsub(doc_number, "A1234567890")
|
26
23
|
body = body.gsub(
|
27
|
-
|
28
|
-
|
24
|
+
"Dokument A1234567890 on kehtiv.",
|
25
|
+
"Dokumenti A1234567890 ei ole välja antud."
|
29
26
|
)
|
30
|
-
|
27
|
+
{ :body => body, :document_number => "A1234567890" }
|
31
28
|
end
|
32
29
|
|
33
30
|
let(:invalid_post_response) do
|
34
31
|
body = File.new('spec/fixtures/invalid_post_response.html').read
|
35
|
-
|
32
|
+
{ :body => body, :document_number => "00000000" }
|
36
33
|
end
|
37
34
|
|
38
35
|
describe '.new' do
|
39
36
|
it 'initializes with a document number' do
|
40
|
-
mock_response_with :get, :get
|
41
37
|
expect(validator).to be
|
42
38
|
expect { validator }.to_not raise_error
|
43
39
|
end
|
@@ -45,16 +41,11 @@ describe Validocno::Validator do
|
|
45
41
|
it 'raises an error without a document number' do
|
46
42
|
expect { Validocno::Validator.new }.to raise_error(ArgumentError)
|
47
43
|
end
|
48
|
-
|
49
|
-
it 'sets csrf_token instance variable' do
|
50
|
-
mock_response_with :get, :get
|
51
|
-
expect(validator.csrf_token).to_not be_nil
|
52
|
-
end
|
53
44
|
end
|
54
45
|
|
55
46
|
describe '#validate' do
|
56
|
-
let(:invalid_doc_number) {
|
57
|
-
let(:expired_doc_number) {
|
47
|
+
let(:invalid_doc_number) { "A1234567890" }
|
48
|
+
let(:expired_doc_number) { "A0111856" }
|
58
49
|
let(:validator_with_invalid) do
|
59
50
|
Validocno::Validator.new(invalid_doc_number)
|
60
51
|
end
|
@@ -64,15 +55,14 @@ describe Validocno::Validator do
|
|
64
55
|
end
|
65
56
|
|
66
57
|
it 'returns hash with :valid and :message keys' do
|
67
|
-
mock_response_with :
|
68
|
-
mock_response_with :post, :valid_nr
|
58
|
+
mock_response_with :valid_nr
|
69
59
|
expect(validator.validate).to have_key(:valid)
|
70
60
|
expect(validator.validate).to have_key(:message)
|
71
61
|
end
|
72
62
|
|
73
63
|
it 'validates document with valid number' do
|
74
|
-
mock_response_with :
|
75
|
-
|
64
|
+
mock_response_with :valid_nr
|
65
|
+
|
76
66
|
expect(validator.validate).to include(
|
77
67
|
:valid => true,
|
78
68
|
:message => "Dokument #{doc_number} on kehtiv."
|
@@ -80,8 +70,7 @@ describe Validocno::Validator do
|
|
80
70
|
end
|
81
71
|
|
82
72
|
it 'validates expired document' do
|
83
|
-
mock_response_with :
|
84
|
-
mock_response_with :post, :expired_nr
|
73
|
+
mock_response_with :expired_nr
|
85
74
|
expect(validator_with_expired.validate).to include(
|
86
75
|
:valid => false,
|
87
76
|
:message => "Dokument #{expired_doc_number} on kehtetu."
|
@@ -89,8 +78,7 @@ describe Validocno::Validator do
|
|
89
78
|
end
|
90
79
|
|
91
80
|
it 'validates document with invalid number' do
|
92
|
-
mock_response_with :
|
93
|
-
mock_response_with :post, :invalid_nr
|
81
|
+
mock_response_with :invalid_nr
|
94
82
|
expect(validator_with_invalid.validate).to include(
|
95
83
|
:valid => false,
|
96
84
|
:message => "Dokumenti #{invalid_doc_number} ei ole välja antud."
|
@@ -98,17 +86,26 @@ describe Validocno::Validator do
|
|
98
86
|
end
|
99
87
|
|
100
88
|
it 'fails if node not found' do
|
101
|
-
mock_response_with :
|
102
|
-
|
103
|
-
expect { validator.validate }.to raise_error(StandardError)
|
89
|
+
mock_response_with :invalid_post
|
90
|
+
expect { invalid_post_validator.validate }.to raise_error(StandardError)
|
104
91
|
end
|
105
92
|
end
|
106
93
|
|
107
94
|
private
|
108
95
|
|
109
|
-
def mock_response_with(
|
110
|
-
|
111
|
-
|
112
|
-
|
96
|
+
def mock_response_with(response)
|
97
|
+
response_result = send("#{response}_response")
|
98
|
+
|
99
|
+
stub_request(:get, "https://www.politsei.ee/qr/?qr=#{response_result[:document_number]}").
|
100
|
+
with(:headers => {
|
101
|
+
"Accept" => "*/*",
|
102
|
+
"Accept-Encoding" => "gzip, deflate",
|
103
|
+
"Host" => "www.politsei.ee",
|
104
|
+
"User-Agent" => "rest-client/2.0.2 (darwin17.2.0 x86_64) ruby/2.1.10p492"
|
105
|
+
}).to_return(
|
106
|
+
:status => 200,
|
107
|
+
:body => response_result[:body],
|
108
|
+
:headers => {}
|
109
|
+
)
|
113
110
|
end
|
114
111
|
end
|
data/spec/validocno_spec.rb
CHANGED
@@ -5,9 +5,6 @@ describe Validocno do
|
|
5
5
|
let(:number) { 'A1234567' }
|
6
6
|
|
7
7
|
it 'calls Validocno::Validator#validate' do
|
8
|
-
allow_any_instance_of(Validocno::Validator).to receive(:csrf_token) {
|
9
|
-
'iiGifsNdIY/OVVbEXnh3hMLtJgXsKomOlWKClE2DozCAo/KdBk0N7g=='
|
10
|
-
}
|
11
8
|
expect_any_instance_of(Validocno::Validator).to receive(:validate)
|
12
9
|
Validocno.validate(number)
|
13
10
|
end
|
data/validocno.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Validocno::VERSION
|
9
9
|
spec.authors = ['Artem Pakk']
|
10
10
|
spec.email = ['artem.pakk@deskrock.ee']
|
11
|
-
spec.summary = 'Estonian ID
|
12
|
-
spec.description = 'Ruby gem to check validity of Estonian ID card'
|
11
|
+
spec.summary = 'Estonian ID validator'
|
12
|
+
spec.description = 'Ruby gem to check validity of Estonian ID card or Estonian Passport'
|
13
13
|
spec.homepage = 'https://github.com/deskrock/validocno'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validocno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Pakk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.20.0
|
97
|
-
description: Ruby gem to check validity of Estonian ID card
|
97
|
+
description: Ruby gem to check validity of Estonian ID card or Estonian Passport
|
98
98
|
email:
|
99
99
|
- artem.pakk@deskrock.ee
|
100
100
|
executables: []
|
@@ -111,7 +111,6 @@ files:
|
|
111
111
|
- lib/validocno/validator.rb
|
112
112
|
- lib/validocno/version.rb
|
113
113
|
- rubocop.yml
|
114
|
-
- spec/fixtures/get_response.html
|
115
114
|
- spec/fixtures/invalid_post_response.html
|
116
115
|
- spec/fixtures/post_response.html
|
117
116
|
- spec/spec_helper.rb
|
@@ -138,12 +137,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
137
|
version: '0'
|
139
138
|
requirements: []
|
140
139
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.7.3
|
142
141
|
signing_key:
|
143
142
|
specification_version: 4
|
144
|
-
summary: Estonian ID
|
143
|
+
summary: Estonian ID validator
|
145
144
|
test_files:
|
146
|
-
- spec/fixtures/get_response.html
|
147
145
|
- spec/fixtures/invalid_post_response.html
|
148
146
|
- spec/fixtures/post_response.html
|
149
147
|
- spec/spec_helper.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
<div id="content1left" class="content" style="min-height: 500px;">
|
2
|
-
<br>
|
3
|
-
<p>
|
4
|
-
Teil on võimalus kontrollida isikut tõendavate dokumentide kehtivust,
|
5
|
-
kui sisestate dokumendi numbri. <b>NB!</b> Dokumendi numbris olevad tähed palume sisestada läbivalt suurte tähtedega.
|
6
|
-
</p>
|
7
|
-
<br>
|
8
|
-
<form name="reqForm" method="post" action="">
|
9
|
-
<input type="hidden" name="cmd" value="request">
|
10
|
-
<input type="hidden" name="csrf" value="iiGifsNdIY/OVVbEXnh3hMLtJgXsKomOlWKClE2DozCAo/KdBk0N7g==">
|
11
|
-
<table class="form">
|
12
|
-
<tbody>
|
13
|
-
<tr>
|
14
|
-
<td class="label">Dokumendi number:</td>
|
15
|
-
<td>
|
16
|
-
<input class="basicInputText" type="text"
|
17
|
-
name="docNumber" size="20" maxlength="20" value="">
|
18
|
-
</td>
|
19
|
-
</tr>
|
20
|
-
<tr>
|
21
|
-
<td colspan="2">
|
22
|
-
</td>
|
23
|
-
</tr>
|
24
|
-
<tr>
|
25
|
-
<td colspan="2">
|
26
|
-
</td>
|
27
|
-
</tr>
|
28
|
-
<tr>
|
29
|
-
<td>
|
30
|
-
</td>
|
31
|
-
<td>
|
32
|
-
<input class="basicInputButton button100px" type="submit"
|
33
|
-
name="subButton" value="Esita päring">
|
34
|
-
</td>
|
35
|
-
</tr>
|
36
|
-
</tbody>
|
37
|
-
</table>
|
38
|
-
</form>
|
39
|
-
<br>
|
40
|
-
</div>
|