Skip to content

Commit 2b78a43

Browse files
committed
8255584: HttpPrincipal::getName returns incorrect name
Reviewed-by: dfuchs
1 parent a6ce6a5 commit 2b78a43

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpPrincipal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public boolean equals(Object another) {
7575
* @return the contents of this principal in the form realm:username
7676
*/
7777
public String getName() {
78-
return username;
78+
return String.format("%s:%s", realm, username);
7979
}
8080

8181
/**

test/jdk/com/sun/net/httpserver/HttpPrincipalTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
public class HttpPrincipalTest {
3737

3838
@Test
39-
public void TestGetters() {
39+
public void testGetters() {
4040
var principal = new HttpPrincipal("test", "123");
41+
4142
assertEquals(principal.getUsername(), "test");
4243
assertEquals(principal.getRealm(), "123");
44+
assertEquals(principal.getName(), "123:test");
45+
assertEquals(principal.toString(), principal.getName());
46+
assertEquals(("test"+"123").hashCode(), principal.hashCode());
4347
}
4448
}

0 commit comments

Comments
 (0)