Merge branch 'stable-3.8'
* stable-3.8:
Don't read git submodule commits during replication
Don't require remote.<name>.url on primary side
Dont copy pull-replication.jar into lib folder in Dockerfile
Adapt to the renamed events-broker.jar build artifact
Don't shade org.eclipse.jgit.transport package
Prevent TimeoutException for remote.<name>.timeout = 0
Change-Id: I1a5c63e061f4a61d4601e125df6142aac0c5db1f
diff --git a/example-setup/broker/Dockerfile b/example-setup/broker/Dockerfile
index acc34b9..0f96cb9 100644
--- a/example-setup/broker/Dockerfile
+++ b/example-setup/broker/Dockerfile
@@ -7,10 +7,9 @@
RUN git config -f /var/gerrit/etc/secure.config --add auth.bearerToken "theSecretBearerToken"
COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/plugins/pull-replication.jar
-COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/lib/pull-replication.jar
COPY --chown=gerrit:gerrit events-kafka.jar /var/gerrit/plugins/events-kafka.jar
-COPY --chown=gerrit:gerrit libevents-broker.jar /var/gerrit/lib/libevents-broker.jar
+COPY --chown=gerrit:gerrit events-broker.jar /var/gerrit/lib/events-broker.jar
COPY --chown=gerrit:gerrit entrypoint.sh /tmp/
COPY --chown=gerrit:gerrit configs/replication.config.template /var/gerrit/etc/
diff --git a/example-setup/broker/README.md b/example-setup/broker/README.md
index d50e097..76ce6dd 100644
--- a/example-setup/broker/README.md
+++ b/example-setup/broker/README.md
@@ -10,7 +10,7 @@
```bash
cp $GERRIT_HOME/bazel-bin/plugins/pull-replication/pull-replication.jar .
cp $GERRIT_HOME/bazel-bin/plugins/events-kafka/events-kafka.jar .
-cp $GERRIT_HOME/bazel-bin/plugins/events-broker/libevents-broker.jar .
+cp $GERRIT_HOME/bazel-bin/plugins/events-broker/events-broker.jar .
```
Start up the application using docker compose:
diff --git a/example-setup/http/Dockerfile b/example-setup/http/Dockerfile
index 3a68b59..afadb4f 100644
--- a/example-setup/http/Dockerfile
+++ b/example-setup/http/Dockerfile
@@ -7,7 +7,6 @@
RUN git config -f /var/gerrit/etc/secure.config --add auth.bearerToken "theSecretBearerToken"
COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/plugins/pull-replication.jar
-COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/lib/pull-replication.jar
COPY --chown=gerrit:gerrit entrypoint.sh /tmp/
COPY --chown=gerrit:gerrit configs/replication.config.template /var/gerrit/etc/
COPY --chown=gerrit:gerrit configs/gerrit.config.template /var/gerrit/etc/
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java
index cd6a0ea..3f03ed6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReader.java
@@ -38,6 +38,7 @@
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Ref;
@@ -214,6 +215,24 @@
return blobs;
}
+ /**
+ * Reads and evaluates the git objects in this revision. The following are filtered out:
+ * <li>DELETE changes
+ * <li>git submodule commits, because the git commit hash is not present in this repo.
+ *
+ * <p>The method keeps track of the total size of all objects it has processed, and verifies
+ * it is below the acceptable threshold.
+ *
+ * @param projectName - the name of the project, used to check total object size threshold
+ * @param refName - the ref name, used to check total object size threshold
+ * @param git - this git repo, used to load the objects
+ * @param totalRefSize - tracks the total size of objects processed
+ * @param diffEntries - a list of the diff entries for this revision
+ * @return a List of `RevisionObjectData`, an object that includes the git object SHA, the git
+ * object change type and the object contents.
+ * @throws MissingObjectException - if the object can't be found
+ * @throws IOException - if processing failed for another reason
+ */
private List<RevisionObjectData> readBlobs(
Project.NameKey projectName,
String refName,
@@ -223,7 +242,7 @@
throws MissingObjectException, IOException {
List<RevisionObjectData> blobs = Lists.newLinkedList();
for (DiffEntry diffEntry : diffEntries) {
- if (!ChangeType.DELETE.equals(diffEntry.getChangeType())) {
+ if (!(ChangeType.DELETE.equals(diffEntry.getChangeType()) || gitSubmoduleCommit(diffEntry))) {
ObjectId diffObjectId = diffEntry.getNewId().toObjectId();
ObjectLoader objectLoader = git.open(diffObjectId);
totalRefSize += objectLoader.getSize();
@@ -237,6 +256,10 @@
return blobs;
}
+ private boolean gitSubmoduleCommit(DiffEntry diffEntry) {
+ return diffEntry.getNewMode().equals(FileMode.GITLINK);
+ }
+
private RevTree getParentTree(Repository git, RevCommit commit)
throws MissingObjectException, IOException {
RevCommit parent = commit.getParent(0);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourceConfigParser.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourceConfigParser.java
index a8799c2..d7ae063 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourceConfigParser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourceConfigParser.java
@@ -17,6 +17,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.server.config.GerritIsReplica;
+import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.replication.ConfigParser;
import com.googlesource.gerrit.plugins.replication.RemoteConfiguration;
import java.net.URISyntaxException;
@@ -32,6 +34,13 @@
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
+ private boolean isReplica;
+
+ @Inject
+ SourceConfigParser(@GerritIsReplica Boolean isReplica) {
+ this.isReplica = isReplica;
+ }
+
/* (non-Javadoc)
* @see com.googlesource.gerrit.plugins.replication.ConfigParser#parseRemotes(org.eclipse.jgit.lib.Config)
*/
@@ -45,7 +54,7 @@
ImmutableList.Builder<RemoteConfiguration> sourceConfigs = ImmutableList.builder();
for (RemoteConfig c : allFetchRemotes(config)) {
- if (c.getURIs().isEmpty()) {
+ if (isReplica && c.getURIs().isEmpty()) {
continue;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommand.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommand.java
index dd06875..991ef07 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommand.java
@@ -91,7 +91,12 @@
try {
state.markAllFetchTasksScheduled();
Future<?> future = source.get().schedule(name, refName, state, fetchType, apiRequestMetrics);
- future.get(source.get().getTimeout(), TimeUnit.SECONDS);
+ int timeout = source.get().getTimeout();
+ if (timeout == 0) {
+ future.get();
+ } else {
+ future.get(timeout, TimeUnit.SECONDS);
+ }
} catch (ExecutionException
| IllegalStateException
| TimeoutException
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/fetch/JGitFetch.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/fetch/JGitFetch.java
index 816d101..1845230 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/fetch/JGitFetch.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/fetch/JGitFetch.java
@@ -18,6 +18,7 @@
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
+import com.googlesource.gerrit.plugins.replication.pull.transport.TransportProvider;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
diff --git a/src/main/java/org/eclipse/jgit/transport/TransportProvider.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProvider.java
similarity index 67%
rename from src/main/java/org/eclipse/jgit/transport/TransportProvider.java
rename to src/main/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProvider.java
index ca15b6c..c52db82 100644
--- a/src/main/java/org/eclipse/jgit/transport/TransportProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProvider.java
@@ -12,8 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.eclipse.jgit.transport;
+package com.googlesource.gerrit.plugins.replication.pull.transport;
+import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
+
+import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.replication.CredentialsFactory;
@@ -23,10 +26,15 @@
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.Transport;
+import org.eclipse.jgit.transport.TransportHttp;
+import org.eclipse.jgit.transport.URIish;
/**
- * This class is responsible for providing a Custom Git HTTP Transport with Bearer Token
- * Authentication or a concrete implementation of {@link org.eclipse.jgit.transport.Transport}.
+ * This class is responsible for setting bearer token header for Bearer Token Authentication using
+ * {@link org.eclipse.jgit.transport.TransportHttp#setAdditionalHeaders(java.util.Map)} method.
*/
@Singleton
public class TransportProvider {
@@ -46,23 +54,14 @@
public Transport open(Repository local, URIish uri)
throws NotSupportedException, TransportException {
- return (bearerToken.isPresent() && TransportHttpWithBearerToken.canHandle(uri))
- ? provideTransportHttpWithBearerToken(local, uri)
- : provideNativeTransport(local, uri);
- }
-
- private Transport provideTransportHttpWithBearerToken(Repository local, URIish uri)
- throws NotSupportedException {
- Transport tn = new TransportHttpWithBearerToken(local, uri, bearerToken.get());
- tn.applyConfig(remoteConfig);
- return tn;
- }
-
- private Transport provideNativeTransport(Repository local, URIish uri)
- throws NotSupportedException, TransportException {
Transport tn = Transport.open(local, uri);
tn.applyConfig(remoteConfig);
- tn.setCredentialsProvider(credentialsProvider);
+ if (tn instanceof TransportHttp && bearerToken.isPresent()) {
+ ((TransportHttp) tn)
+ .setAdditionalHeaders(ImmutableMap.of(HDR_AUTHORIZATION, "Bearer " + bearerToken.get()));
+ } else {
+ tn.setCredentialsProvider(credentialsProvider);
+ }
return tn;
}
}
diff --git a/src/main/java/org/eclipse/jgit/transport/TransportHttpWithBearerToken.java b/src/main/java/org/eclipse/jgit/transport/TransportHttpWithBearerToken.java
deleted file mode 100644
index 68ff6f8..0000000
--- a/src/main/java/org/eclipse/jgit/transport/TransportHttpWithBearerToken.java
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2022 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.eclipse.jgit.transport;
-
-import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableSet;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Set;
-import org.eclipse.jgit.errors.NotSupportedException;
-import org.eclipse.jgit.lib.ProgressMonitor;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.transport.http.HttpConnection;
-
-/**
- * This is a hack in order to allow git over http/https with Bearer Token Authentication.
- *
- * <p>Currently {@link org.eclipse.jgit.transport.TransportHttp} does NOT provide Bearer Token
- * Authentication and unfortunately it is not possible to extend the functionality because some
- * classes, methods and instance variables are private or protected. This package in the pull
- * replication plugin provides the visibility needed and allows to extend the functionality.
- *
- * <p>It is important to mention that in the case of git push operation, this class cannot be used
- * because the push operation needs to initialise a push hook: {@link
- * org.eclipse.jgit.transport.Transport#push(ProgressMonitor, Collection, OutputStream)} and it is
- * defined as a private in the code.
- */
-public class TransportHttpWithBearerToken extends TransportHttp {
-
- private static final String SCHEME_HTTP = "http";
- private static final String SCHEME_HTTPS = "https";
- private static final Set<String> SCHEMES_ALLOWED = ImmutableSet.of(SCHEME_HTTP, SCHEME_HTTPS);
- private final String bearerToken;
-
- public TransportHttpWithBearerToken(Repository local, URIish uri, String bearerToken)
- throws NotSupportedException {
- super(local, uri);
- this.bearerToken = bearerToken;
- }
-
- protected HttpConnection httpOpen(String method, URL u, AcceptEncoding acceptEncoding)
- throws IOException {
- HttpConnection conn = super.httpOpen(method, u, acceptEncoding);
- conn.setRequestProperty(HDR_AUTHORIZATION, "Bearer " + bearerToken); // $NON-NLS-1$
- return conn;
- }
-
- /**
- * This method copies the behaviour of {@link
- * org.eclipse.jgit.transport.TransportProtocol#canHandle(URIish, Repository, String)} in the case
- * of {@link org.eclipse.jgit.transport.TransportHttp} where scheme, host and path are compulsory.
- */
- public static boolean canHandle(URIish uri) {
- return SCHEMES_ALLOWED.contains(uri.getScheme())
- && !Strings.isNullOrEmpty(uri.getHost())
- && !Strings.isNullOrEmpty(uri.getPath());
- }
-}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReaderIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReaderIT.java
index 1d8520f..fcd9b19 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReaderIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/RevisionReaderIT.java
@@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth8;
import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
+import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.PushOneCommit.Result;
import com.google.gerrit.acceptance.TestPlugin;
import com.google.gerrit.acceptance.UseLocalDisk;
@@ -199,6 +200,39 @@
Truth8.assertThat(revisionDataOption).isEmpty();
}
+ @Test
+ public void shouldFilterOutGitSubmoduleCommitsWhenReadingTheBlobs() throws Exception {
+ String submodulePath = "submodule_path";
+ final ObjectId GitSubmoduleCommit =
+ ObjectId.fromString("93e2901bc0b4719ef6081ee6353b49c9cdd97614");
+
+ PushOneCommit push =
+ pushFactory
+ .create(admin.newIdent(), testRepo)
+ .addGitSubmodule(submodulePath, GitSubmoduleCommit);
+ PushOneCommit.Result pushResult = push.to("refs/for/master");
+ pushResult.assertOkStatus();
+ Change.Id changeId = pushResult.getChange().getId();
+ String refName = RefNames.patchSetRef(pushResult.getPatchSetId());
+
+ CommentInput comment = createCommentInput(1, 0, 1, 1, "Test comment");
+
+ ReviewInput reviewInput = new ReviewInput();
+ reviewInput.comments = ImmutableMap.of(Patch.COMMIT_MSG, ImmutableList.of(comment));
+ gApi.changes().id(changeId.get()).current().review(reviewInput);
+
+ Optional<RevisionData> revisionDataOption =
+ refObjectId(refName).flatMap(objId -> readRevisionFromObjectUnderTest(refName, objId, 0));
+
+ assertThat(revisionDataOption.isPresent()).isTrue();
+ RevisionData revisionData = revisionDataOption.get();
+
+ assertThat(revisionData.getBlobs()).hasSize(1);
+ RevisionObjectData blobObject = revisionData.getBlobs().get(0);
+ assertThat(blobObject.getType()).isEqualTo(Constants.OBJ_BLOB);
+ assertThat(blobObject.getSha1()).isNotEqualTo(GitSubmoduleCommit.getName());
+ }
+
private CommentInput createCommentInput(
int startLine, int startCharacter, int endLine, int endCharacter, String message) {
CommentInput comment = new CommentInput();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommandTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommandTest.java
index c093719..de8036e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommandTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchCommandTest.java
@@ -125,7 +125,7 @@
@Test
public void shouldUpdateStateWhenInterruptedException()
throws InterruptedException, ExecutionException, TimeoutException {
- when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(new InterruptedException());
+ when(future.get()).thenThrow(new InterruptedException());
when(source.schedule(projectName, REF_NAME_TO_FETCH, state, SYNC, Optional.empty()))
.thenReturn(future);
@@ -140,8 +140,7 @@
@Test
public void shouldUpdateStateWhenExecutionException()
throws InterruptedException, ExecutionException, TimeoutException {
- when(future.get(anyLong(), eq(TimeUnit.SECONDS)))
- .thenThrow(new ExecutionException(new Exception()));
+ when(future.get()).thenThrow(new ExecutionException(new Exception()));
when(source.schedule(projectName, REF_NAME_TO_FETCH, state, SYNC, Optional.empty()))
.thenReturn(future);
@@ -159,6 +158,7 @@
when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(new TimeoutException());
when(source.schedule(projectName, REF_NAME_TO_FETCH, state, SYNC, Optional.empty()))
.thenReturn(future);
+ when(source.getTimeout()).thenReturn(1);
TimeoutException e =
assertThrows(
diff --git a/src/test/java/org/eclipse/jgit/transport/TransportProviderTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProviderTest.java
similarity index 86%
rename from src/test/java/org/eclipse/jgit/transport/TransportProviderTest.java
rename to src/test/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProviderTest.java
index ea70c40..0b28c03 100644
--- a/src/test/java/org/eclipse/jgit/transport/TransportProviderTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/transport/TransportProviderTest.java
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.eclipse.jgit.transport;
+package com.googlesource.gerrit.plugins.replication.pull.transport;
import static com.google.common.truth.Truth.assertThat;
import static org.eclipse.jgit.transport.HttpConfig.EXTRA_HEADER;
@@ -28,6 +28,11 @@
import java.util.Optional;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.TransferConfig;
+import org.eclipse.jgit.transport.Transport;
+import org.eclipse.jgit.transport.TransportHttp;
+import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -69,7 +74,9 @@
URIish urIish = new URIish("http://some-host/some-path");
Transport transport = transportProvider.open(repository, urIish);
- assertThat(transport).isInstanceOf(TransportHttpWithBearerToken.class);
+
+ // TODO(davido): We cannot access headers to check that the bearer token is set.
+ assertThat(transport).isInstanceOf(TransportHttp.class);
}
@Test
@@ -84,7 +91,8 @@
URIish urIish = new URIish("ssh://some-host/some-path");
Transport transport = transportProvider.open(repository, urIish);
- assertThat(transport).isNotInstanceOf(TransportHttpWithBearerToken.class);
+
+ assertThat(transport).isNotInstanceOf(TransportHttp.class);
}
@Test
@@ -98,6 +106,6 @@
URIish urIish = new URIish("ssh://some-host/some-path");
Transport transport = transportProvider.open(repository, urIish);
- assertThat(transport).isNotInstanceOf(TransportHttpWithBearerToken.class);
+ assertThat(transport).isNotInstanceOf(TransportHttp.class);
}
}
diff --git a/src/test/java/org/eclipse/jgit/transport/TransportHttpWithBearerTokenTest.java b/src/test/java/org/eclipse/jgit/transport/TransportHttpWithBearerTokenTest.java
deleted file mode 100644
index 5bf1047..0000000
--- a/src/test/java/org/eclipse/jgit/transport/TransportHttpWithBearerTokenTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (C) 2022 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.eclipse.jgit.transport;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import java.net.URISyntaxException;
-import org.junit.Test;
-
-public class TransportHttpWithBearerTokenTest {
-
- @Test
- public void cannotHandleURIWhenSchemaIsNeitherHttpNorHttps() throws URISyntaxException {
- URIish uriUnderTest = new URIish("some-uri").setScheme(null);
- boolean result = TransportHttpWithBearerToken.canHandle(uriUnderTest);
- assertThat(result).isFalse();
- }
-
- @Test
- public void cannotHandleURIWhenHostIsNotPresent() throws URISyntaxException {
- URIish uriUnderTest = new URIish("some-uri").setScheme("http").setHost(null);
- boolean result = TransportHttpWithBearerToken.canHandle(uriUnderTest);
- assertThat(result).isFalse();
- }
-
- @Test
- public void cannotHandleURIWhenPathIsNotPresent() throws URISyntaxException {
- URIish uriUnderTest =
- new URIish("some-uri").setScheme("http").setHost("some-host").setPath(null);
- boolean result = TransportHttpWithBearerToken.canHandle(uriUnderTest);
- assertThat(result).isFalse();
- }
-
- @Test
- public void canHandleURIWhenIsWellFormed() throws URISyntaxException {
- URIish uriUnderTest = new URIish("http://some-host/some-path");
- boolean result = TransportHttpWithBearerToken.canHandle(uriUnderTest);
- assertThat(result).isTrue();
- }
-}