|
30 | 30 | topics = attribute('topics') |
31 | 31 | subscriptions = attribute('subscriptions') |
32 | 32 | region = attribute('region') |
| 33 | +audit_config = attribute('audit_config') |
33 | 34 |
|
34 | 35 | # Role pairs (arrays of length = 2) |
35 | 36 | basic_roles = attribute('basic_roles') |
|
259 | 260 | end |
260 | 261 | end |
261 | 262 | end |
| 263 | + |
| 264 | +# Audit config |
| 265 | + |
| 266 | +control 'audit-log-config' do |
| 267 | + title 'Test if audit log config is correct' |
| 268 | + |
| 269 | + describe command ("gcloud projects get-iam-policy #{project_id} --format='json(auditConfigs)'") do |
| 270 | + its(:exit_status) { should eq 0 } |
| 271 | + its(:stderr) { should eq '' } |
| 272 | + let!(:data) do |
| 273 | + if subject.exit_status == 0 |
| 274 | + JSON.parse(subject.stdout) |
| 275 | + else |
| 276 | + {} |
| 277 | + end |
| 278 | + end |
| 279 | + describe "check auditConfigs count" do |
| 280 | + it "has two auditConfigs" do |
| 281 | + expect(data["auditConfigs"].length).to eq 2 |
| 282 | + end |
| 283 | + end |
| 284 | + describe "check members email" do |
| 285 | + it "has correct exemptedMembers" do |
| 286 | + data["auditConfigs"].each do |config| |
| 287 | + expect([audit_config[0]["exempted_members"][0], audit_config[1]["exempted_members"][0]]).to include( |
| 288 | + config["auditLogConfigs"][0]["exemptedMembers"][0] |
| 289 | + ) |
| 290 | + end |
| 291 | + end |
| 292 | + end |
| 293 | + describe "check log type " do |
| 294 | + it "has correct log type" do |
| 295 | + expect(data["auditConfigs"][0]["auditLogConfigs"][0]["logType"]).to eq audit_config[0]["log_type"] |
| 296 | + end |
| 297 | + end |
| 298 | + describe "check services " do |
| 299 | + it "has correct Services" do |
| 300 | + data["auditConfigs"].each do |config| |
| 301 | + expect([audit_config[0]["service"],audit_config[1]["service"]]).to include ( |
| 302 | + config["service"] |
| 303 | + ) |
| 304 | + end |
| 305 | + end |
| 306 | + end |
| 307 | + end |
| 308 | +end |
0 commit comments