email-authentication 0.1.0 → 0.1.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/Gemfile.lock +2 -0
- data/lib/email-authentication/base.rb +40 -12
- data/test/coverage/index.html +1 -1
- data/test/test_address.rb +11 -8
- data/test/test_mx_records.rb +40 -0
- metadata +2 -2
- data/test/test_normal.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb0630ec5b87bbab71968a26df1a4c883caee26
|
4
|
+
data.tar.gz: b806b6540c3b104d86961379944b8b5a0c913239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a75a3e97e638d0a4a4a9e4f8c6fb50d5d3a628fa1d868fa79313bf7b8bf8ddbcf56aa1a10d3bc64c89584b55c67eb6337bec22ba8b7a6399547555c35cf63fc
|
7
|
+
data.tar.gz: d4abdf831492b3711a415ff9e6abab9e32f8641a74931ffe4abdcd3de17b66a9eaebc91178465a059d02f2fa9983b4ba6a564a66058c67b13aa019ec8462f945
|
data/Gemfile.lock
CHANGED
@@ -2,12 +2,14 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
email-authentication (0.1.0)
|
5
|
+
dnsruby
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
10
|
codeclimate-test-reporter (0.1.1)
|
10
11
|
simplecov (>= 0.7.1, < 1.0.0)
|
12
|
+
dnsruby (1.54)
|
11
13
|
minitest (5.0.8)
|
12
14
|
multi_json (1.8.0)
|
13
15
|
simplecov (0.7.1)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
|
2
|
+
require 'dnsruby'
|
3
|
+
include Dnsruby
|
4
4
|
|
5
5
|
# Use the system configured nameservers to run a query
|
6
6
|
|
7
7
|
module EmailAuthentication
|
8
8
|
class Base
|
9
|
-
attr_accessor :address, :mx, :message
|
9
|
+
attr_accessor :address, :mx, :message, :domain
|
10
10
|
def debug
|
11
11
|
true
|
12
12
|
end
|
@@ -16,25 +16,53 @@ module EmailAuthentication
|
|
16
16
|
self.address=address.to_s
|
17
17
|
@flag=true
|
18
18
|
end
|
19
|
+
# this needs work. Anyone who can improve the regex i would be happy
|
19
20
|
def check_format
|
20
|
-
|
21
|
+
@@email_regex = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/i
|
22
|
+
res=(@address =~ @@email_regex)
|
23
|
+
puts " res is #{res}"
|
24
|
+
if res
|
25
|
+
[true,"format ok"]
|
26
|
+
else
|
27
|
+
[false,"format failed"]
|
28
|
+
end
|
21
29
|
end
|
22
|
-
|
30
|
+
# cache the dns resolver
|
23
31
|
def resolver
|
24
|
-
@resolver =
|
25
|
-
# @resolver = Dnsruby::Resolver.new if @resolver==nil
|
32
|
+
@resolver = Dnsruby::Resolver.new if @resolver==nil
|
26
33
|
@resolver
|
27
34
|
end
|
28
|
-
|
35
|
+
# check the mx domain
|
29
36
|
def check_mx
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
domain=self.address.split('@')
|
38
|
+
@domain = domain[1]
|
39
|
+
puts "domain is #{domain}"
|
40
|
+
flag=false
|
41
|
+
if @domain!=nil
|
42
|
+
begin
|
43
|
+
ret = self.resolver.query(@domain, Types.MX)
|
44
|
+
if ret.answer!=nil and ret.rcode=='NOERROR'
|
45
|
+
@mx=ret.answer.first.exchange.to_s if ret.answer!=nil
|
46
|
+
msg= "mx record #{self.mx}"
|
47
|
+
puts msg
|
48
|
+
flag=true
|
49
|
+
end
|
50
|
+
rescue Dnsruby::NXDomain
|
51
|
+
msg="non existing domain #{@domain}"
|
52
|
+
puts msg
|
53
|
+
end
|
54
|
+
|
55
|
+
else
|
56
|
+
msg="nil domain"
|
57
|
+
end
|
58
|
+
puts "ret is #{ret.inspect}"
|
59
|
+
[flag,msg]
|
33
60
|
end
|
34
|
-
|
61
|
+
# need to think about this and check the domain via telnet
|
35
62
|
def check_smtp
|
36
63
|
[true,"smtp ok"]
|
37
64
|
end
|
65
|
+
# run all the checks
|
38
66
|
def check(address)
|
39
67
|
self.set_address(address)
|
40
68
|
@message=[]
|
data/test/coverage/index.html
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<img src="./assets/0.7.1/loading.gif" alt="loading"/>
|
15
15
|
</div>
|
16
16
|
<div id="wrapper" style="display:none;">
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="2013-10-
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2013-10-20T15:28:45+08:00">2013-10-20T15:28:45+08:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
data/test/test_address.rb
CHANGED
@@ -31,10 +31,9 @@ class EmailAuthenticationTest < Minitest::Test
|
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def test_goodemail
|
35
35
|
success,msg= @f.check(@success)
|
36
|
-
assert success,"check did not succeed"
|
37
|
-
|
36
|
+
assert success,"check did not succeed #{msg}"
|
38
37
|
end
|
39
38
|
def test_resolver_onlyonce
|
40
39
|
res=@f.resolver
|
@@ -43,16 +42,20 @@ class EmailAuthenticationTest < Minitest::Test
|
|
43
42
|
|
44
43
|
end
|
45
44
|
#check a particular format
|
46
|
-
def
|
45
|
+
def test_checkformat_good
|
47
46
|
@f.set_address(@success)
|
48
47
|
success,msg= @f.check_format
|
49
48
|
assert success,"check did not succeed"
|
50
49
|
|
51
50
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def test_bademails
|
52
|
+
['test','test#sed', 'test@jack'].each { |e|
|
53
|
+
@f.set_address(e)
|
54
|
+
success,msg= @f.check_format
|
55
|
+
assert !success,"check did succeed but it should not for #{e}"
|
56
|
+
}
|
57
|
+
|
58
|
+
end
|
56
59
|
|
57
60
|
|
58
61
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
puts File.dirname(__FILE__)
|
2
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
3
|
+
|
4
|
+
|
5
|
+
class EmailMXAuthenticationTest < Minitest::Test
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@f=EmailAuthentication::Base.new
|
9
|
+
@success='scott.sproule@ficonab.com'
|
10
|
+
@failruntimeerror=[nil,""]
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_good_domain
|
15
|
+
@f.set_address(@success)
|
16
|
+
success,msg= @f.check_mx
|
17
|
+
assert success,"check did not succeed"
|
18
|
+
assert @f.mx!=nil, "mx should be set"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_bad_domain
|
23
|
+
@f.set_address('test@baddomainxx23345.com')
|
24
|
+
success,msg= @f.check_mx
|
25
|
+
assert !success,"check did not succeed"
|
26
|
+
|
27
|
+
end
|
28
|
+
def test_bad_domain2
|
29
|
+
@f.set_address('test@baddom ainxx23345.com')
|
30
|
+
success,msg= @f.check_mx
|
31
|
+
assert !success,"check did not succeed"
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email-authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Sproule
|
@@ -77,7 +77,7 @@ files:
|
|
77
77
|
- test/coverage/index.html
|
78
78
|
- test/test_address.rb
|
79
79
|
- test/test_helper.rb
|
80
|
-
- test/
|
80
|
+
- test/test_mx_records.rb
|
81
81
|
- bin/emailcheck.rb
|
82
82
|
- Gemfile
|
83
83
|
- Gemfile.lock
|
data/test/test_normal.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
puts File.dirname(__FILE__)
|
2
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
3
|
-
|
4
|
-
|
5
|
-
class NormalTest < Minitest::Test
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@f=Randprize::Base.new
|
9
|
-
@pm=Randprize::ManagePrizes.new
|
10
|
-
@headstails={ "T"=> {'odds'=> 2,'name'=>'win tails','value'=>0},"H"=> {'odds'=> 2,'name'=>'win heads','value'=>1}}
|
11
|
-
@dice={}
|
12
|
-
1.upto(6) {|i| @dice[i.to_s]= {'odds'=> 6,'name'=>"rolled #{i}",'value'=>1} }
|
13
|
-
@large={ "GP"=> {'odds'=> 100,'name'=>'grandprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>1}}
|
14
|
-
@exlarge={ "GP"=> {'odds'=> 50000,'name'=>'grandprize','value'=>50000},"2nd"=> {'odds'=> 5000,'name'=>'2ndprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>0}}
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
def test_randomprize_forrandom
|
20
|
-
steps=5000
|
21
|
-
count=0
|
22
|
-
1.upto(steps) do
|
23
|
-
@pm.prize_list(@headstails)
|
24
|
-
prizes=[]
|
25
|
-
@pm.myprizelist.each {|k| #puts "K is #{k}"
|
26
|
-
prizes << k[1]}
|
27
|
-
aprize=@pm.random_prize
|
28
|
-
assert prizes.include?(aprize), "prize should be from the list"
|
29
|
-
#puts "count #{count} aprize #{aprize}"
|
30
|
-
count=aprize['value']+count
|
31
|
-
end
|
32
|
-
ratio=(count.to_f/steps)*100
|
33
|
-
assert (49..51).include?(ratio.round), "ratio wrong #{ratio.round} count #{count}"
|
34
|
-
end
|
35
|
-
def test_dize
|
36
|
-
steps=5000
|
37
|
-
count=0
|
38
|
-
hcount={}
|
39
|
-
1.upto(6) {|i| hcount["rolled #{i}"]=0}
|
40
|
-
|
41
|
-
1.upto(steps) do
|
42
|
-
@pm.prize_list(@dice)
|
43
|
-
prizes=[]
|
44
|
-
@pm.myprizelist.each {|k| #puts "K is #{k}"
|
45
|
-
prizes << k[1]}
|
46
|
-
aprize=@pm.random_prize
|
47
|
-
assert prizes.include?(aprize), "prize should be from the list"
|
48
|
-
#puts "count #{count} aprize #{aprize}"
|
49
|
-
hcount[aprize['name']]=hcount[aprize['name']]+1
|
50
|
-
end
|
51
|
-
# ratio=(count.to_f/steps)*100
|
52
|
-
# assert (49..51).include?(ratio.round), "ratio wrong #{ratio.round} count #{count}"
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|