Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] File mode tests for regular files pass only with specific umask values #1328

Closed
kevin85421 opened this issue Dec 4, 2023 · 0 comments · Fixed by #1323
Closed

[Bug] File mode tests for regular files pass only with specific umask values #1328

kevin85421 opened this issue Dec 4, 2023 · 0 comments · Fixed by #1323
Labels
bug Something isn't working

Comments

@kevin85421
Copy link
Contributor

kevin85421 commented Dec 4, 2023

Describe the bug

  • As shown in the following code snippet, the function ensureFiles checks the file mode for both regular files and secret files.

    if f.Type == file.TypeRegular {
    Expect(info.Mode()).To(Equal(os.FileMode(0o644)))
    } else {
    Expect(info.Mode()).To(Equal(os.FileMode(0o640)))
    }

  • The function ReplaceFiles in nginx/file/manager.go creates files by internally calling os.Create, which, by default, creates files with mode 0666 (before applying umask). See the source code of os.Create for more details.

  • The function writeFile changes the mode of secret files to 0640 by calling chmod, but does nothing for regular files. Hence, the check Expect(info.Mode()).To(Equal(os.FileMode(0o644))) in nginx/file/manager_test.go only passes for umask with specific values.

  • In my environment, the umask value is 002. Therefore, the mode for regular files will be 0666 - 0002 = 0664, causing the unit test to fail. In the following screenshot, 420 is 0o644, and 436 is 0o664.
    Screen Shot 2023-12-02 at 6 05 36 PM

To Reproduce

  • Step 1: Set umask to 002.
  • Step 2: Run make unit-test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants