scorecard icon indicating copy to clipboard operation
scorecard copied to clipboard

:bug: BUG found in the Security-Policy unit test & more testcases are needed

Open aidenwang9867 opened this issue 4 years ago • 1 comments

Describe the bug When a single not-a-security-policy file is added as a testcase to the Security-Policy unit test (https://github.com/ossf/scorecard/blob/main/checks/security_policy_test.go), it reports a GitHub token env var not set error, then triggers a nil pointer deference error, and the test fails.

Reproduction steps Steps to reproduce the behavior:

  1. Make sure your GitHub token is correctly set (https://github.com/ossf/scorecard#authentication);
  2. Pull the latest main branch git clone https://github.com/ossf/scorecard.git and then go to file scorecard/checks/security_policy_test.go;
  3. Directly run the Security-Policy test, and it should be okay;
  4. Add a testcase for failure testing (security policy not detected) such as:
{
  name: "Fail Case: not a security policy file",
  files: []string {
  "notASecurityPolicyFile.go",
  },
  want: scut.TestReturn{
  Score:        0,
  NumberOfInfo: 0,
  },
},
  1. Run the test again, it fails and reports GitHub token env var is not set at first, then comes to panic: runtime error: invalid memory address or nil pointer dereference

Expected behavior The expected behavior is it would give a score of 0 to this testcase since func isSecurityPolicyFilename (https://github.com/ossf/scorecard/blob/main/checks/raw/security_policy.go#L89) should return false because it's not a match in the security policy files list, then, it should still pass all the tests.

Additional context

  1. (Not sure) The BUG here might relate to the mockRepo at https://github.com/ossf/scorecard/blob/main/checks/security_policy_test.go#L123-L132. I'll look into it later.
  2. Since the files is a type of []string, maybe we could put some test cases into one files rather than one filename per files - this might make the unit test cleaner.
  3. When multiple filenames, including security-policy and non-security-policy ones, are in var files, it passes the unit test.
  4. Extra testcases for failure testing (score of zero) are needed for this part.

aidenwang9867 avatar May 24 '22 19:05 aidenwang9867

I can take this issue. I will add a regression case for a non-security-policy file, make the test fixture fail closed without requiring a GitHub token, and run the focused Security-Policy test suite before opening a PR.

lolcubaba31 avatar Sep 14 '26 17:09 lolcubaba31