aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Jakob Buchgraber <buchgr@google.com>2018-02-08 12:19:57 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-08 12:21:43 -0800
commitcf3f81aef7c32019d70cbce218a64a03276268f0 (patch)
tree91e53806bed5441f4e93c43c999ac1ace3ce0c8f /src/test/java
parent1c6d061ea448ee19022f6e609099515a25a5a131 (diff)
remote: Add support for HTTP Basic Auth
Closes #4609. PiperOrigin-RevId: 185032751
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandlerTest.java60
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpDownloadHandlerTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpUploadHandlerTest.java2
3 files changed, 62 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandlerTest.java b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandlerTest.java
new file mode 100644
index 0000000000..bb4e2266f5
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandlerTest.java
@@ -0,0 +1,60 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// 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 com.google.devtools.build.lib.remote.blobstore.http;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.embedded.EmbeddedChannel;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpRequest;
+import java.io.ByteArrayOutputStream;
+import java.net.URI;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.Mockito;
+
+/** Tests for {@link AbstractHttpHandlerTest}. */
+@RunWith(JUnit4.class)
+public abstract class AbstractHttpHandlerTest {
+
+ @Test
+ public void basicAuthShouldWork() throws Exception {
+ URI uri = new URI("http://user:password@does.not.exist/foo");
+ EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null));
+ ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream());
+ DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream());
+ ChannelPromise writePromise = ch.newPromise();
+ ch.writeOneOutbound(cmd, writePromise);
+
+ HttpRequest request = ch.readOutbound();
+ assertThat(request.headers().get(HttpHeaderNames.AUTHORIZATION))
+ .isEqualTo("Basic dXNlcjpwYXNzd29yZA==");
+ }
+
+ @Test
+ public void basicAuthShouldNotEnabled() throws Exception {
+ URI uri = new URI("http://does.not.exist/foo");
+ EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null));
+ ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream());
+ DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream());
+ ChannelPromise writePromise = ch.newPromise();
+ ch.writeOneOutbound(cmd, writePromise);
+
+ HttpRequest request = ch.readOutbound();
+ assertThat(request.headers().contains(HttpHeaderNames.AUTHORIZATION)).isFalse();
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpDownloadHandlerTest.java b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpDownloadHandlerTest.java
index da16587870..ca544ee553 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpDownloadHandlerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpDownloadHandlerTest.java
@@ -40,7 +40,7 @@ import org.mockito.Mockito;
/** Tests for {@link HttpDownloadHandler}. */
@RunWith(JUnit4.class)
-public class HttpDownloadHandlerTest {
+public class HttpDownloadHandlerTest extends AbstractHttpHandlerTest {
private static final URI CACHE_URI = URI.create("http://storage.googleapis.com:80/cache-bucket");
diff --git a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpUploadHandlerTest.java b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpUploadHandlerTest.java
index 9ab56509b9..27914da542 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpUploadHandlerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpUploadHandlerTest.java
@@ -37,7 +37,7 @@ import org.junit.runners.JUnit4;
/** Tests for {@link HttpUploadHandler}. */
@RunWith(JUnit4.class)
-public class HttpUploadHandlerTest {
+public class HttpUploadHandlerTest extends AbstractHttpHandlerTest {
private static final URI CACHE_URI = URI.create("http://storage.googleapis.com:80/cache-bucket");