]> git.openstreetmap.org Git - rails.git/blob - test/models/acl_test.rb
Merge remote-tracking branch 'upstream/pull/4559'
[rails.git] / test / models / acl_test.rb
1 require "test_helper"
2
3 class AclTest < ActiveSupport::TestCase
4   def test_k_required
5     acl = create(:acl)
6     assert_predicate acl, :valid?
7     acl.k = nil
8     assert_not_predicate acl, :valid?
9   end
10
11   def test_no_account_creation_by_subnet
12     assert_not Acl.no_account_creation("192.168.1.1")
13     create(:acl, :address => "192.168.0.0/16", :k => "no_account_creation")
14     assert Acl.no_account_creation("192.168.1.1")
15   end
16
17   def test_no_account_creation_by_domain
18     assert_not Acl.no_account_creation("192.168.1.1", :domain => "example.com")
19     assert_not Acl.no_account_creation("192.168.1.1", :domain => "test.example.com")
20     create(:acl, :domain => "example.com", :k => "no_account_creation")
21     assert Acl.no_account_creation("192.168.1.1", :domain => "example.com")
22     assert Acl.no_account_creation("192.168.1.1", :domain => "test.example.com")
23   end
24
25   def test_no_account_creation_by_mx
26     assert_not Acl.no_account_creation("192.168.1.1", :mx => "mail.example.com")
27     create(:acl, :mx => "mail.example.com", :k => "no_account_creation")
28     assert Acl.no_account_creation("192.168.1.1", :mx => "mail.example.com")
29   end
30
31   def test_allow_account_creation_by_subnet
32     assert_not Acl.allow_account_creation("192.168.1.1")
33     create(:acl, :address => "192.168.0.0/16", :k => "allow_account_creation")
34     assert Acl.allow_account_creation("192.168.1.1")
35   end
36
37   def test_allow_account_creation_by_domain
38     assert_not Acl.allow_account_creation("192.168.1.1", :domain => "example.com")
39     assert_not Acl.allow_account_creation("192.168.1.1", :domain => "test.example.com")
40     create(:acl, :domain => "example.com", :k => "allow_account_creation")
41     assert Acl.allow_account_creation("192.168.1.1", :domain => "example.com")
42     assert Acl.allow_account_creation("192.168.1.1", :domain => "test.example.com")
43   end
44
45   def test_allow_account_creation_by_mx
46     assert_not Acl.allow_account_creation("192.168.1.1", :mx => "mail.example.com")
47     create(:acl, :mx => "mail.example.com", :k => "allow_account_creation")
48     assert Acl.allow_account_creation("192.168.1.1", :mx => "mail.example.com")
49   end
50
51   def test_no_note_comment_by_domain
52     assert_not Acl.no_note_comment("192.168.1.1", "example.com")
53     assert_not Acl.no_note_comment("192.168.1.1", "test.example.com")
54     create(:acl, :domain => "example.com", :k => "no_note_comment")
55     assert Acl.no_note_comment("192.168.1.1", "example.com")
56     assert Acl.no_note_comment("192.168.1.1", "test.example.com")
57   end
58
59   def test_no_trace_download_by_domain
60     assert_not Acl.no_trace_download("192.168.1.1", "example.com")
61     assert_not Acl.no_trace_download("192.168.1.1", "test.example.com")
62     create(:acl, :domain => "example.com", :k => "no_trace_download")
63     assert Acl.no_trace_download("192.168.1.1", "example.com")
64     assert Acl.no_trace_download("192.168.1.1", "test.example.com")
65   end
66 end