Skip to content

Make non-writable file test independent of user privileges - #5609

Open
nippyclouding wants to merge 1 commit into
spring-projects:mainfrom
nippyclouding:GH-3892
Open

nippyclouding wants to merge 1 commit into
spring-projects:mainfrom
nippyclouding:GH-3892

Conversation

@nippyclouding

Copy link
Copy Markdown

testOpenWithNonWritableFile marks a real file read-only and assumes File.canWrite() returns false. This fails when the JVM runs as root, which can still write to the file.

Use a mocked existing, non-writable file and resource so the test continues to verify that opening the writer rejects the file, independently of filesystem permissions. This also removes the fixed target/no-such-file.foo fixture.

Closes #3892

Validation on Temurin JDK 25:

  • ./mvnw -B -ntp -pl spring-batch-infrastructure -Dtest=FlatFileItemWriterTests test: 32 tests passed as a regular user on macOS.
  • Ran the original test in a Linux container as root: reproduced the Should be readonly file failure. Ran the modified test class in the same environment: all 32 tests passed, with no skips.
  • ./mvnw -B -ntp package

Mock an existing non-writable file instead of relying on filesystem permissions, which root can bypass.

Closes spring-projectsgh-3892

Signed-off-by: Lee Sang Won <nippyclouding@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure in a Docker container

1 participant