Java Code Examples for org.eclipse.jgit.transport.CredentialItem#InformationalMessage

The following examples show how to use org.eclipse.jgit.transport.CredentialItem#InformationalMessage . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSslTrustItems() throws URISyntaxException {
	URIish uri = new URIish("https://example.com/repo.git");
	CredentialItem message = new CredentialItem.InformationalMessage(
			JGitText.get().sslFailureTrustExplanation);
	CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType(
			JGitText.get().sslTrustNow);
	CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType(
			JGitText.get().sslTrustAlways);

	boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri,
			message, trustNow, trustAlways);

	assertThat(getSuccessful).as(
			"SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping")
			.isTrue();
	assertThat(trustNow.getValue()).as(
			"SkipSSlValidationCredentialsProvider should trust the current repo operation")
			.isTrue();
	assertThat(trustAlways.getValue())
			.as("We should not globally skip all SSL validation").isFalse();
}
 
Example 2
Source File: JGitCredentialsProvider.java    From mOrgAnd with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean get(URIish uri, CredentialItem... items)
        throws UnsupportedCredentialItem {
    for (CredentialItem item : items) {
        if (item instanceof CredentialItem.Username) {
            ((CredentialItem.Username) item).setValue(username);
        } else if (item instanceof CredentialItem.Password) {
            ((CredentialItem.Password) item).setValue(password.toCharArray());
        } else if (item instanceof CredentialItem.StringType) {
            ((CredentialItem.StringType) item).setValue(password);
        } else if (item instanceof CredentialItem.InformationalMessage) {
            throw new UnsupportedCredentialItem(uri, "Not supported");
        } else if (item instanceof CredentialItem.YesNoType) {
            // TODO handle strict host key checking here
            throw new UnsupportedCredentialItem(uri, "Not supported");
        } else {
            throw new UnsupportedCredentialItem(uri, "Not supported");
        }
    }
    return true;
}
 
Example 3
Source File: GitSkipSslValidationCredentialsProvider.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supports(CredentialItem... items) {
	List<CredentialItem> unprocessedItems = new ArrayList<>();

	for (CredentialItem item : items) {
		if (item instanceof CredentialItem.InformationalMessage
				&& item.getPromptText() != null && item.getPromptText()
						.contains(JGitText.get().sslFailureTrustExplanation)) {
			continue;
		}

		if (item instanceof CredentialItem.YesNoType && item.getPromptText() != null
				&& (item.getPromptText().equals(JGitText.get().sslTrustNow)
						|| item.getPromptText()
								.startsWith(stripFormattingPlaceholders(
										JGitText.get().sslTrustForRepo))
						|| item.getPromptText()
								.equals(JGitText.get().sslTrustAlways))) {
			continue;
		}

		unprocessedItems.add(item);
	}

	return unprocessedItems.isEmpty() || (this.delegate != null && this.delegate
			.supports(unprocessedItems.toArray(new CredentialItem[0])));
}
 
Example 4
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupportsSslFailureInformationalMessage() {
	CredentialItem informationalMessage = new CredentialItem.InformationalMessage(
			"text " + JGitText.get().sslFailureTrustExplanation + " more text");
	assertThat(this.skipSslValidationCredentialsProvider
			.supports(informationalMessage)).as(
					"GitSkipSslValidationCredentialsProvider should always support SSL failure InformationalMessage")
					.isTrue();

	informationalMessage = new CredentialItem.InformationalMessage("unrelated");
	assertThat(this.skipSslValidationCredentialsProvider
			.supports(informationalMessage)).as(
					"GitSkipSslValidationCredentialsProvider should not support unrelated InformationalMessage items")
					.isFalse();
}
 
Example 5
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSslTrustItemsWithLocalRepo() throws URISyntaxException {
	URIish uri = new URIish("https://example.com/repo.git");
	CredentialItem message = new CredentialItem.InformationalMessage(
			JGitText.get().sslFailureTrustExplanation);
	CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType(
			JGitText.get().sslTrustNow);
	CredentialItem.YesNoType trustForRepo = new CredentialItem.YesNoType(
			JGitText.get().sslTrustForRepo);
	CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType(
			JGitText.get().sslTrustAlways);

	boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri,
			message, trustNow, trustForRepo, trustAlways);

	assertThat(getSuccessful).as(
			"SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping")
			.isTrue();
	assertThat(trustNow.getValue()).as(
			"SkipSSlValidationCredentialsProvider should trust the current repo operation")
			.isTrue();
	assertThat(trustForRepo.getValue())
			.as("Future operations on this repository should also be trusted")
			.isTrue();
	assertThat(trustAlways.getValue())
			.as("We should not globally skip all SSL validation").isFalse();
}
 
Example 6
Source File: CredentialsProviderImplTest.java    From git-client-plugin with MIT License 5 votes vote down vote up
@Test
public void testThrowsUnsupportedOperationException() {
    CredentialItem.InformationalMessage message = new CredentialItem.InformationalMessage("Some info");
    assertFalse(provider.supports(message));
    assertThrows(UnsupportedCredentialItem.class,
                 () -> {
                     provider.get(uri, message);
                 });
}