Skip to content
Snippets Groups Projects
Select Git revision
  • 4bc7414df2fa67ad51e1512d3ef1ea5ddbb99c1b
  • main default protected
  • next
  • chore/update-static-data
  • renovate/main-redis-5.x
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.53.1
  • 41.53.0
  • 41.52.3
  • 41.52.2
  • 41.52.1
  • 41.52.0
  • 41.51.2
  • 41.51.1
  • 41.51.0
  • 41.50.0
  • 41.49.1
  • 41.49.0
  • 41.48.1
  • 41.48.0
  • 41.47.1
  • 41.47.0
  • 41.46.8
  • 41.46.7
  • 41.46.6
  • 41.46.5
41 results

index.spec.ts

Blame
  • check_test.go 2.60 KiB
    // Copyright © 2017-2019 Aqua Security Software Ltd. <info@aquasec.com>
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //     http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    package check
    
    import (
    	"os/exec"
    	"testing"
    )
    
    func TestCheck_Run(t *testing.T) {
    	type TestCase struct {
    		check    Check
    		Expected State
    	}
    
    	testCases := []TestCase{
    		{check: Check{Type: MANUAL}, Expected: WARN},
    		{check: Check{Type: "skip"}, Expected: INFO},
    
    		{check: Check{Scored: false}, Expected: WARN}, // Not scored checks with no type, or not scored failing tests are marked warn
    		{
    			check: Check{ // Not scored checks with passing tests are marked pass
    				Scored: false,
    				Audit:  ":", Commands: []*exec.Cmd{exec.Command("")},
    				Tests: &tests{TestItems: []*testItem{&testItem{}}},
    			},
    			Expected: PASS,
    		},
    
    		{check: Check{Scored: true}, Expected: WARN},                  // If there are no tests in the check, warn
    		{check: Check{Scored: true, Tests: &tests{}}, Expected: FAIL}, // If there are tests that are not passing, fail
    		{
    			check: Check{ // Scored checks with passing tests are marked pass
    				Scored: true,
    				Audit:  ":", Commands: []*exec.Cmd{exec.Command("")},
    				Tests: &tests{TestItems: []*testItem{&testItem{}}},
    			},
    			Expected: PASS,
    		},
    	}
    	for _, testCase := range testCases {
    
    		testCase.check.run()
    
    		if testCase.check.State != testCase.Expected {
    			t.Errorf("test failed, expected %s, actual %s\n", testCase.Expected, testCase.check.State)
    		}
    	}
    }
    
    func TestCheckAuditConfig(t *testing.T) {
    
    	cases := []struct {
    		*Check
    		expected State
    	}{
    		{
    			controls.Groups[1].Checks[0],
    			"PASS",
    		},
    		{
    			controls.Groups[1].Checks[1],
    			"FAIL",
    		},
    		{
    			controls.Groups[1].Checks[2],
    			"FAIL",
    		},
    		{
    			controls.Groups[1].Checks[3],
    			"PASS",
    		},
    		{
    			controls.Groups[1].Checks[4],
    			"FAIL",
    		},
    		{
    			controls.Groups[1].Checks[5],
    			"PASS",
    		},
    		{
    			controls.Groups[1].Checks[6],
    			"FAIL",
    		},
    		{
    			controls.Groups[1].Checks[7],
    			"PASS",
    		},
    		{
    			controls.Groups[1].Checks[8],
    			"FAIL",
    		},
    	}
    
    	for _, c := range cases {
    		c.run()
    		if c.State != c.expected {
    			t.Errorf("%s, expected:%v, got:%v\n", c.Text, c.expected, c.State)
    		}
    	}
    }