Skip to content

Commit

Permalink
Merge pull request #631 from fcojfernandez/logged-user-no-ui
Browse files Browse the repository at this point in the history
Make check of logged-in user independent of UI
  • Loading branch information
amuniz authored Jan 20, 2021
2 parents 7af44e7 + 1334531 commit ce2ff85
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/main/java/org/jenkinsci/test/acceptance/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,9 @@ public static Matcher<Jenkins> hasLoggedInUser(final String user) {
return new Matcher<Jenkins>("has logged in user %s", user) {
@Override
public boolean matchesSafely(final Jenkins jenkins) {
try {
jenkins.find(by.href("/user/" + user));
return true;
} catch (NoSuchElementException e) {
return false;
}
final User currentUser = jenkins.getCurrentUser();
// if the user is not logged, currentUser can be not null with a null id
return currentUser != null && currentUser.id() != null && currentUser.id().equals(user);
}

@Override
Expand All @@ -219,12 +216,9 @@ public static Matcher<Login> loggedInAs(final String user) {
return new Matcher<Login>("has logged in user %s", user) {
@Override
public boolean matchesSafely(final Login login) {
try {
login.find(by.href("/user/" + user));
return true;
} catch (NoSuchElementException e) {
return false;
}
final User currentUser = login.getJenkins().getCurrentUser();
// if the user is not logged, currentUser can be not null with a null id
return currentUser != null && currentUser.id() != null && currentUser.id().equals(user);
}

@Override
Expand Down

0 comments on commit ce2ff85

Please sign in to comment.