|
38 | 38 | end |
39 | 39 | end |
40 | 40 |
|
| 41 | + describe "allowed internal rules" do |
| 42 | + it "should contain ICMP rule" do |
| 43 | + expect(data["allowed"]).to include({"IPProtocol" => "icmp"}) |
| 44 | + end |
| 45 | + |
| 46 | + it "should contain UDP rule" do |
| 47 | + expect(data["allowed"]).to include({"IPProtocol" => "udp"}) |
| 48 | + end |
| 49 | + |
| 50 | + it "should contain TCP rule" do |
| 51 | + expect(data["allowed"]).to include({"IPProtocol"=>"tcp", "ports"=>["8080", "1000-2000"]}) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + # Custom rules |
| 57 | + describe command("gcloud compute firewall-rules describe allow-backend-to-databases --project=#{project_id} --format=json") do |
| 58 | + its(:exit_status) { should eq 0 } |
| 59 | + its(:stderr) { should eq '' } |
| 60 | + |
| 61 | + let(:data) do |
| 62 | + if subject.exit_status == 0 |
| 63 | + JSON.parse(subject.stdout) |
| 64 | + else |
| 65 | + {} |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe "Custom TAG rule" do |
| 70 | + it "has backend tag as source" do |
| 71 | + expect(data).to include( |
| 72 | + "sourceTags" => ["backed"] |
| 73 | + ) |
| 74 | + end |
| 75 | + |
| 76 | + it "has databases tag as target" do |
| 77 | + expect(data).to include( |
| 78 | + "targetTags" => ["databases"] |
| 79 | + ) |
| 80 | + end |
| 81 | + |
| 82 | + it "has expected TCP rule" do |
| 83 | + expect(data["allowed"]).to include( |
| 84 | + { |
| 85 | + "IPProtocol" => "tcp", |
| 86 | + "ports" => ["3306", "5432", "1521", "1433"] |
| 87 | + } |
| 88 | + ) |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | +describe command("gcloud compute firewall-rules describe deny-ingress-6534-6566 --project=#{project_id} --format=json") do |
| 94 | + its(:exit_status) { should eq 0 } |
| 95 | + its(:stderr) { should eq '' } |
| 96 | + |
| 97 | + let(:data) do |
| 98 | + if subject.exit_status == 0 |
| 99 | + JSON.parse(subject.stdout) |
| 100 | + else |
| 101 | + {} |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + describe "deny-ingress-6534-6566" do |
| 106 | + it "should be disabled" do |
| 107 | + expect(data).to include( |
| 108 | + "disabled" => true |
| 109 | + ) |
| 110 | + end |
| 111 | + |
| 112 | + it "has 0.0.0.0/0 source range" do |
| 113 | + expect(data).to include( |
| 114 | + "sourceRanges" => ["0.0.0.0/0"] |
| 115 | + ) |
| 116 | + end |
| 117 | + |
| 118 | + it "has expected TCP rules" do |
| 119 | + expect(data["denied"]).to include( |
| 120 | + { |
| 121 | + "IPProtocol" => "tcp", |
| 122 | + "ports" => ["6534-6566"] |
| 123 | + } |
| 124 | + ) |
| 125 | + end |
| 126 | + |
| 127 | + it "has expected UDP rules" do |
| 128 | + expect(data["denied"]).to include( |
| 129 | + { |
| 130 | + "IPProtocol" => "udp", |
| 131 | + "ports" => ["6534-6566"] |
| 132 | + } |
| 133 | + ) |
| 134 | + end |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + |
| 139 | +describe command("gcloud compute firewall-rules describe allow-all-admin-sa --project=#{project_id} --format=json") do |
| 140 | + its(:exit_status) { should eq 0 } |
| 141 | + its(:stderr) { should eq '' } |
| 142 | + |
| 143 | + let(:data) do |
| 144 | + if subject.exit_status == 0 |
| 145 | + JSON.parse(subject.stdout) |
| 146 | + else |
| 147 | + {} |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + describe "allow-all-admin-sa" do |
| 152 | + it "should be enabled" do |
| 153 | + expect(data).to include( |
| 154 | + "disabled" => false |
| 155 | + ) |
| 156 | + end |
| 157 | + |
| 158 | + it "should has correct source SA" do |
| 159 | + expect(data["sourceServiceAccounts"]).to eq(["[email protected]"]) |
| 160 | + end |
| 161 | + |
| 162 | + it "should has priority 30" do |
| 163 | + expect(data["priority"]).to eq(30) |
| 164 | + end |
| 165 | + |
| 166 | + it "has expected TCP rules" do |
| 167 | + expect(data["allowed"]).to include( |
| 168 | + { |
| 169 | + "IPProtocol" => "tcp" |
| 170 | + } |
| 171 | + ) |
| 172 | + end |
| 173 | + |
| 174 | + it "has expected UDP rules" do |
| 175 | + expect(data["allowed"]).to include( |
| 176 | + { |
| 177 | + "IPProtocol" => "udp" |
| 178 | + } |
| 179 | + ) |
| 180 | + end |
| 181 | + end |
41 | 182 | end |
42 | 183 |
|
43 | 184 | end |
| 185 | + |
0 commit comments