Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
olenagerasimova committed Sep 29, 2020
1 parent ef7fad2 commit dcb535d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/artipie/LoggingPermissions.java
Expand Up @@ -67,9 +67,13 @@ public LoggingPermissions(final Permissions origin, final Level level) {
public boolean allowed(final Authentication.User user, final String action) {
final boolean res = this.origin.allowed(user, action);
if (res) {
Logger.log(this.level, this.origin, "Operation '%s' allowed for '%s'", action, user);
Logger.log(
this.level, this.origin, "Operation '%s' allowed for '%s'", action, user.name()
);
} else {
Logger.log(this.level, this.origin, "Operation '%s' denied for '%s'", action, user);
Logger.log(
this.level, this.origin, "Operation '%s' denied for '%s'", action, user.name()
);
}
return res;
}
Expand Down
33 changes: 15 additions & 18 deletions src/test/java/com/artipie/YamlPermissionsTest.java
Expand Up @@ -48,33 +48,31 @@ class YamlPermissionsTest {

@Test
void johnCanDownloadDeployAndDelete() throws Exception {
final String uname = "john";
final Authentication.User user = new Authentication.User("john");
MatcherAssert.assertThat(
this.permissions(),
new AllOf<YamlPermissions>(
new ListOf<org.hamcrest.Matcher<? super YamlPermissions>>(
// @checkstyle LineLengthCheck (4 lines)
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "delete"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "download"); }),
new MatcherOf<>(perm -> !perm.allowed(new Authentication.User(uname), "install"))
new MatcherOf<>(perm -> { return perm.allowed(user, "delete"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "download"); }),
new MatcherOf<>(perm -> !perm.allowed(user, "install"))
)
)
);
}

@Test
void janeCanDownloadAndDeploy() throws Exception {
final String uname = "jane";
final Authentication.User user = new Authentication.User("jane");
MatcherAssert.assertThat(
this.permissions(),
new AllOf<YamlPermissions>(
new ListOf<org.hamcrest.Matcher<? super YamlPermissions>>(
// @checkstyle LineLengthCheck (4 lines)
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "download"); }),
new MatcherOf<>(perm -> !perm.allowed(new Authentication.User(uname), "install")),
new MatcherOf<>(perm -> !perm.allowed(new Authentication.User(uname), "update"))
new MatcherOf<>(perm -> { return perm.allowed(user, "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "download"); }),
new MatcherOf<>(perm -> !perm.allowed(user, "install")),
new MatcherOf<>(perm -> !perm.allowed(user, "update"))
)
)
);
Expand All @@ -90,16 +88,15 @@ void anyoneCanDownload() throws Exception {

@Test
void adminCanDoAnything() throws Exception {
final String uname = "admin";
final Authentication.User user = new Authentication.User("admin");
MatcherAssert.assertThat(
this.permissions(),
new AllOf<YamlPermissions>(
new ListOf<org.hamcrest.Matcher<? super YamlPermissions>>(
// @checkstyle LineLengthCheck (4 lines)
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "delete"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "download"); }),
new MatcherOf<>(perm -> { return perm.allowed(new Authentication.User(uname), "install"); })
new MatcherOf<>(perm -> { return perm.allowed(user, "delete"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "deploy"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "download"); }),
new MatcherOf<>(perm -> { return perm.allowed(user, "install"); })
)
)
);
Expand Down

0 comments on commit dcb535d

Please sign in to comment.