]> git.openstreetmap.org Git - rails.git/blob - test/system/acls_test.rb
Merge remote-tracking branch 'upstream/pull/7406'
[rails.git] / test / system / acls_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class AclsTest < ApplicationSystemTestCase
6   test "index shows a placeholder when there are no acls" do
7     sign_in_as(create(:administrator_user))
8
9     visit acls_path
10     assert_title "ACLs"
11     assert_text "No ACLs to show."
12   end
13
14   test "index lists acls with formatted addresses" do
15     create(:acl, :address => "192.0.2.0/24", :k => "no_account_creation", :v => "spam")
16     create(:acl, :address => "198.51.100.7", :k => "no_note_comment")
17     create(:acl, :domain => "example.com", :mx => "mail.example.com", :k => "allow_account_creation")
18     sign_in_as(create(:administrator_user))
19
20     visit acls_path
21     within_table "acl_list" do
22       assert_selector "tbody tr", :count => 3
23       assert_selector "tr", :text => "192.0.2.0/24 no_account_creation spam"
24       assert_selector "tr", :text => "198.51.100.7 no_note_comment"
25       assert_selector "tr", :text => "example.com mail.example.com allow_account_creation"
26     end
27   end
28
29   test "index shows newest acls first and pages through older ones" do
30     1.upto(25) { |n| create(:acl, :k => "no_account_creation", :v => "entry-#{n}") }
31     sign_in_as(create(:administrator_user))
32
33     visit acls_path
34     within_table "acl_list" do
35       assert_selector "tbody tr", :count => 20
36       assert_selector "tbody tr:first-child", :text => "entry-25"
37       assert_selector "tbody tr:last-child", :text => "entry-6"
38       assert_no_text "entry-5"
39     end
40
41     click_on "Older ACLs", :match => :first
42     within_table "acl_list" do
43       assert_selector "tbody tr", :count => 5
44       assert_selector "tbody tr:first-child", :text => "entry-5"
45       assert_selector "tbody tr:last-child", :text => "entry-1"
46       assert_no_text "entry-6"
47     end
48     assert_no_link "Older ACLs"
49
50     click_on "Newer ACLs", :match => :first
51     within_table "acl_list" do
52       assert_selector "tbody tr", :count => 20
53       assert_selector "tbody tr:first-child", :text => "entry-25"
54     end
55     assert_no_link "Newer ACLs"
56   end
57
58   test "create an acl" do
59     sign_in_as(create(:administrator_user))
60
61     visit acls_path
62     click_on "New ACL"
63     assert_title "New ACL"
64
65     fill_in "Address", :with => "192.0.2.0/24"
66     fill_in "Domain", :with => "example.com"
67     fill_in "MX server", :with => "mail.example.com"
68     fill_in "Key", :with => "no_account_creation"
69     fill_in "Value", :with => "spam"
70     click_on "Create ACL"
71
72     assert_text "ACL created."
73     within_table "acl_list" do
74       assert_selector "tr", :text => "192.0.2.0/24 example.com mail.example.com no_account_creation spam"
75     end
76   end
77
78   test "create an acl with an invalid address" do
79     sign_in_as(create(:administrator_user))
80
81     visit new_acl_path
82     fill_in "Address", :with => "not-an-address"
83     fill_in "Key", :with => "no_account_creation"
84     click_on "Create ACL"
85
86     assert_title "New ACL"
87     assert_text "is invalid"
88     assert_field "Address", :with => "not-an-address"
89     assert_equal 0, Acl.count
90   end
91
92   test "edit an acl" do
93     create(:acl, :address => "192.0.2.0/24", :k => "no_account_creation")
94     sign_in_as(create(:administrator_user))
95
96     visit acls_path
97     within_table "acl_list" do
98       click_on "Edit"
99     end
100     assert_title "Editing ACL"
101     assert_field "Address", :with => "192.0.2.0/24"
102     assert_field "Key", :with => "no_account_creation"
103
104     fill_in "Address", :with => "198.51.100.7"
105     fill_in "Key", :with => "no_note_comment"
106     click_on "Update ACL"
107
108     assert_text "ACL updated."
109     within_table "acl_list" do
110       assert_selector "tr", :text => "198.51.100.7 no_note_comment"
111       assert_no_text "192.0.2.0/24"
112     end
113   end
114
115   test "delete an acl" do
116     create(:acl, :address => "192.0.2.0/24", :k => "no_account_creation")
117     sign_in_as(create(:administrator_user))
118
119     visit acls_path
120     accept_confirm do
121       click_on "Delete"
122     end
123
124     assert_text "ACL deleted."
125     assert_text "No ACLs to show."
126     assert_equal 0, Acl.count
127   end
128 end