This repository has been archived by the owner on May 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for URIs with user info but no password for the ProxySe…
…rvlet (#4051) Signed-off-by: Kai Kreuzer <kai@openhab.org>
- Loading branch information
1 parent
705a18c
commit c813f25
Showing
3 changed files
with
70 additions
and
5 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
63 changes: 63 additions & 0 deletions
63
...i.test/src/test/java/org/eclipse/smarthome/ui/internal/proxy/ProxyServletServiceTest.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,63 @@ | ||
/** | ||
* Copyright (c) 2014-2017 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.smarthome.ui.internal.proxy; | ||
|
||
import static org.mockito.Matchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.eclipse.jetty.client.api.Request; | ||
import org.eclipse.jetty.http.HttpHeader; | ||
import org.eclipse.jetty.util.B64Code; | ||
import org.eclipse.jetty.util.StringUtil; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for the {@link ProxyServletService} class. | ||
* | ||
* @author Kai Kreuzer - Initial contribution | ||
* | ||
*/ | ||
public class ProxyServletServiceTest { | ||
|
||
static private ProxyServletService service; | ||
|
||
@Before | ||
public void setUp() { | ||
service = new ProxyServletService(); | ||
} | ||
|
||
@Test | ||
public void testMaybeAppendAuthHeaderWithFullCredentials() throws URISyntaxException { | ||
Request request = mock(Request.class); | ||
URI uri = new URI("http://testuser:testpassword@127.0.0.1:8080/content"); | ||
service.maybeAppendAuthHeader(uri, request); | ||
verify(request).header(HttpHeader.AUTHORIZATION, | ||
"Basic " + B64Code.encode("testuser:testpassword", StringUtil.__ISO_8859_1)); | ||
} | ||
|
||
@Test | ||
public void testMaybeAppendAuthHeaderWithoutPassword() throws URISyntaxException { | ||
Request request = mock(Request.class); | ||
URI uri = new URI("http://testuser@127.0.0.1:8080/content"); | ||
service.maybeAppendAuthHeader(uri, request); | ||
verify(request).header(HttpHeader.AUTHORIZATION, | ||
"Basic " + B64Code.encode("testuser:", StringUtil.__ISO_8859_1)); | ||
} | ||
|
||
@Test | ||
public void testMaybeAppendAuthHeaderWithoutCredentials() throws URISyntaxException { | ||
Request request = mock(Request.class); | ||
URI uri = new URI("http://127.0.0.1:8080/content"); | ||
service.maybeAppendAuthHeader(uri, request); | ||
verify(request, never()).header(any(HttpHeader.class), anyString()); | ||
} | ||
} |
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