forked from jenkinsci/acceptance-test-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
040ab3b
commit 66f2942
Showing
4 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jenkinsci.test.acceptance.po; | ||
|
||
/** | ||
* Security Realm provided by oic-auth plugin | ||
*/ | ||
@Describable({"Login with Openid Connect", "Login with Openid Connect"}) | ||
public class OicAuthSecurityRealm extends SecurityRealm { | ||
|
||
public OicAuthSecurityRealm(GlobalSecurityConfig context, String path) { | ||
super(context, path); | ||
} | ||
|
||
public void configureClient(String clientId, String clientSecret) { | ||
control("clientId").set(clientId); | ||
control("clientSecret").set(clientSecret); | ||
} | ||
|
||
public void setAutomaticConfiguration(String wellKnownEndpoint) { | ||
control(by.radioButton("Automatic configuration")).click(); | ||
control("wellKnownOpenIDConfigurationUrl").set(wellKnownEndpoint); | ||
} | ||
|
||
public void logoutFromOpenidProvider(boolean logout) { | ||
Control check = control(by.checkbox("Logout from OpenID Provider")); | ||
if (logout) { | ||
check.check(); | ||
} else { | ||
check.uncheck(); | ||
} | ||
} | ||
|
||
public void setPostLogoutUrl(String postLogoutUrl) { | ||
control("postLogoutRedirectUrl").set(postLogoutUrl); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/org/jenkinsci/test/acceptance/utils/keycloack/KeycloakUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.jenkinsci.test.acceptance.utils.keycloack; | ||
|
||
import java.net.URL; | ||
|
||
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl; | ||
import org.jenkinsci.test.acceptance.utils.ElasticTime; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import jakarta.inject.Inject; | ||
|
||
public class KeycloakUtils extends CapybaraPortingLayerImpl { | ||
|
||
@Inject | ||
public WebDriver driver; | ||
@Inject | ||
public ElasticTime time; | ||
|
||
public KeycloakUtils() { | ||
super(null); | ||
} | ||
|
||
public void open(URL url) { | ||
visit(url); | ||
} | ||
|
||
public void login(String user) { | ||
login(user, user); | ||
} | ||
|
||
public void login(String user, String passwd) { | ||
waitFor(by.id("username"), 5); | ||
find(by.id("username")).sendKeys(user); | ||
find(by.id("password")).sendKeys(passwd); | ||
find(by.id("kc-login")).click(); | ||
} | ||
|
||
|
||
public User getUser(String keycloakUrl, String realm) { | ||
driver.get(String.format("%s/realms/%s/account", keycloakUrl, realm)); | ||
|
||
waitFor(by.id("username"), 5); | ||
String username = find(by.id("username")).getDomProperty("value"); | ||
String email = find(by.id("email")).getDomProperty("value"); | ||
String firstName = find(by.id("firstName")).getDomProperty("value"); | ||
String lastName = find(by.id("lastName")).getDomProperty("value"); | ||
|
||
|
||
return new User(null /* id not available in this page*/, username, email, firstName, lastName); | ||
} | ||
|
||
public void logout(User user) { | ||
final String caption = user.getFirstName() + " " + user.getLastName(); | ||
waitFor(by.button(caption), 5); | ||
clickButton(caption); | ||
waitFor(by.button("Sign out")); | ||
clickButton("Sign out"); | ||
} | ||
|
||
public static class User { | ||
|
||
private final String id; | ||
private final String userName; | ||
private final String email; | ||
private final String firstName; | ||
private final String lastName; | ||
|
||
public User(String id, String userName, String email, String firstName, String lastName) { | ||
this.id = id; | ||
this.userName = userName; | ||
this.email = email; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getUserName() { | ||
return userName; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
} | ||
} |
Oops, something went wrong.