Testing not authenticated access to Docker repository
@@ -43,13 +43,6 @@ import org.junit.jupiter.api.io.TempDir;
* Integration test for auth in local Docker repositories.
*
* @since 0.10
- * @todo #449:30min Check negative auth cases.
- * `DockerLocalAuthIT` contains tests for authenticated access
- * when there is enough permissions for certain operations.
- * However, to ensure that auth works as expected we need to check cases for auth failure:
- * - attempt to access with unknown user
- * - attempt to write with user without write permissions
- * - attempt to read with user without read permissions
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@DockerClientSupport
@@ -154,6 +147,22 @@ final class DockerLocalAuthIT {
);
}
+ @Test
+ void shouldFailPushIfAnonymous() throws Exception {
+ this.logout();
+ final DockerClient.Result result = this.client.runUnsafe("push", this.image.remote());
+ MatcherAssert.assertThat(
+ "Return code is not 0",
+ result.returnCode(),
+ new IsNot<>(new IsEqual<>(0))
+ );
+ MatcherAssert.assertThat(
+ "Error reported",
+ result.output(),
+ new StringContains("no basic auth credentials")
+ );
+ }
+
@Test
void shouldPullPushed() throws Exception {
this.login(ArtipieServer.ALICE);
@@ -190,6 +199,26 @@ final class DockerLocalAuthIT {
);
}
+ @Test
+ void shouldFailPullIfAnonymous() throws Exception {
+ this.login(ArtipieServer.ALICE);
+ this.client.run("push", this.image.remote());
+ this.client.run("image", "rm", this.image.name());
+ this.client.run("image", "rm", this.image.remote());
+ this.logout();
+ final DockerClient.Result result = this.client.runUnsafe("pull", this.image.remote());
+ MatcherAssert.assertThat(
+ "Return code is not 0",
+ result.returnCode(),
+ new IsNot<>(new IsEqual<>(0))
+ );
+ MatcherAssert.assertThat(
+ "Error reported",
+ result.output(),
+ new StringContains("no basic auth credentials")
+ );
+ }
+
private Image prepareImage() throws Exception {
this.login(ArtipieServer.ALICE);
final Image source = new Image.ForOs();
@@ -209,4 +238,8 @@ final class DockerLocalAuthIT {
private void login(final ArtipieServer.User user) throws Exception {
this.client.login(user.name(), user.password(), this.repository);
}
+
+ private void logout() throws Exception {
+ this.client.run("logout", this.repository);
+ }
}
