1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class AclsTest < ApplicationSystemTestCase
6 test "index shows a placeholder when there are no acls" do
7 sign_in_as(create(:administrator_user))
11 assert_text "No ACLs to show."
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))
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"
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))
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"
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"
48 assert_no_link "Older ACLs"
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"
55 assert_no_link "Newer ACLs"
58 test "create an acl" do
59 sign_in_as(create(:administrator_user))
63 assert_title "New ACL"
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"
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"
78 test "create an acl with an invalid address" do
79 sign_in_as(create(:administrator_user))
82 fill_in "Address", :with => "not-an-address"
83 fill_in "Key", :with => "no_account_creation"
86 assert_title "New ACL"
87 assert_text "is invalid"
88 assert_field "Address", :with => "not-an-address"
89 assert_equal 0, Acl.count
93 create(:acl, :address => "192.0.2.0/24", :k => "no_account_creation")
94 sign_in_as(create(:administrator_user))
97 within_table "acl_list" do
100 assert_title "Editing ACL"
101 assert_field "Address", :with => "192.0.2.0/24"
102 assert_field "Key", :with => "no_account_creation"
104 fill_in "Address", :with => "198.51.100.7"
105 fill_in "Key", :with => "no_note_comment"
106 click_on "Update ACL"
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"
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))
124 assert_text "ACL deleted."
125 assert_text "No ACLs to show."
126 assert_equal 0, Acl.count