use of org.finos.legend.sdlc.server.gitlab.mode.GitLabMode in project legend-sdlc by finos.
the class TestGitLabProjectId method testEquality.
@Test
public void testEquality() {
GitLabMode[] modes = GitLabMode.values();
for (GitLabMode mode : modes) {
for (int i = 0; i < 1024; i++) {
GitLabProjectId projectId = GitLabProjectId.newProjectId(mode, i);
Assert.assertEquals(projectId, projectId);
Assert.assertEquals(projectId, GitLabProjectId.newProjectId(mode, i));
Assert.assertNotEquals(projectId, GitLabProjectId.newProjectId(mode, i + 1));
Assert.assertNotEquals(projectId, GitLabProjectId.newProjectId(mode, i - 1));
Assert.assertNotEquals(projectId, GitLabProjectId.newProjectId(modes[(mode.ordinal() + 1) % modes.length], i));
}
}
}
use of org.finos.legend.sdlc.server.gitlab.mode.GitLabMode in project legend-sdlc by finos.
the class GitLabApiTestSetupUtil method prepareGitLabUserContextHelper.
/**
* Authenticates to GitLab and creates a test GitLabUserContext.
*
* @param username the name of user for whom we create this context.
* @param password the password of user for whom we create this context.
* @param hostUrl the url of the test host.
* @param hostScheme the scheme of the test host.
* @param hostHost the test host.
* @param hostPort the port (if necessary) of the test host.
*/
public static GitLabUserContext prepareGitLabUserContextHelper(String username, String password, String hostUrl, String hostScheme, String hostHost, Integer hostPort) throws LegendSDLCServerException {
GitLabMode gitLabMode = GitLabMode.PROD;
TestHttpServletRequest httpServletRequest = new TestHttpServletRequest();
TestGitLabSession session = new TestGitLabSession(username);
GitLabApi oauthGitLabApi;
Version version;
try {
oauthGitLabApi = GitLabApi.oauth2Login(hostUrl, username, password, null, null, true);
Assert.assertNotNull(oauthGitLabApi);
version = oauthGitLabApi.getVersion();
} catch (GitLabApiException e) {
StringBuilder builder = new StringBuilder("Error instantiating GitLabApi via OAuth2; response status: ").append(e.getHttpStatus());
StringTools.appendThrowableMessageIfPresent(builder, e, "; error message: ");
if (e.hasValidationErrors()) {
builder.append("; validation error(s): ").append(e.getValidationErrors());
}
throw new LegendSDLCServerException(builder.toString(), e);
}
String oauthToken = oauthGitLabApi.getAuthToken();
LOGGER.info("Retrieved access token: {}", oauthToken);
Assert.assertNotNull(version);
GitLabServerInfo gitLabServerInfo = GitLabServerInfo.newServerInfo(hostScheme, hostHost, hostPort);
GitLabAppInfo gitLabAppInfo = GitLabAppInfo.newAppInfo(gitLabServerInfo, null, null, null);
GitLabModeInfo gitLabModeInfo = GitLabModeInfo.newModeInfo(gitLabMode, gitLabAppInfo);
session.setGitLabToken(gitLabMode, oauthToken, TokenType.OAUTH2_ACCESS);
session.setModeInfo(gitLabModeInfo);
LegendSDLCWebFilter.setSessionAttributeOnServletRequest(httpServletRequest, session);
GitLabAuthorizerManager authorizerManager = GitLabAuthorizerManager.newManager(Collections.emptyList());
return new GitLabUserContext(httpServletRequest, null, authorizerManager);
}
use of org.finos.legend.sdlc.server.gitlab.mode.GitLabMode in project legend-sdlc by finos.
the class GitLabTokenManager method putAllFromToken.
void putAllFromToken(Token.TokenReader reader) {
synchronized (this.tokens) {
for (int size = reader.getInt(); size > 0; size--) {
// Read values
String modeName = reader.getString();
String appId = reader.getString();
String typeName = reader.getString();
String token = reader.getString();
if ((modeName != null) && (appId != null) && (typeName != null) && (token != null)) {
// Get mode and token type
GitLabMode mode;
TokenType type;
try {
mode = GitLabMode.valueOf(modeName);
type = TokenType.valueOf(typeName);
} catch (IllegalArgumentException e) {
// unknown mode or token type - token will be ignored
continue;
}
// Check the mode info
GitLabModeInfo modeInfo = this.modeInfos.getModeInfo(mode);
if ((modeInfo != null) && appId.equals(modeInfo.getAppInfo().getAppId())) {
this.tokens.put(mode, GitLabToken.newGitLabToken(type, token));
}
}
}
}
}
use of org.finos.legend.sdlc.server.gitlab.mode.GitLabMode in project legend-sdlc by finos.
the class TestGitLabMode method testGetMode_CaseSensitive.
@Test
public void testGetMode_CaseSensitive() {
for (GitLabMode mode : GitLabMode.values()) {
Assert.assertEquals(mode, GitLabMode.getMode(mode.name(), true));
try {
GitLabMode.getMode(mode.name().toLowerCase(), true);
Assert.fail("Expected exception: " + mode.name().toLowerCase());
} catch (IllegalArgumentException e) {
Assert.assertEquals("Unknown mode: " + mode.name().toLowerCase(), e.getMessage());
}
}
}
use of org.finos.legend.sdlc.server.gitlab.mode.GitLabMode in project legend-sdlc by finos.
the class TestGitLabMode method testGetMode_CaseInsensitive.
@Test
public void testGetMode_CaseInsensitive() {
for (GitLabMode mode : GitLabMode.values()) {
Assert.assertEquals(mode, GitLabMode.getMode(mode.name(), false));
Assert.assertEquals(mode, GitLabMode.getMode(mode.name().toLowerCase(), false));
}
Assert.assertEquals(GitLabMode.PROD, GitLabMode.getMode("pRoD", false));
Assert.assertEquals(GitLabMode.UAT, GitLabMode.getMode("UAt", false));
}
Aggregations