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