Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix auth token decoder in Bolt v3 HelloMessage
- Share meta data map decoding function between v1 InitMessage and v3 HelloMessage - Share auth token decoder unittests
- Loading branch information
1 parent
37d145b
commit be6d909
Showing
5 changed files
with
177 additions
and
87 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
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
104 changes: 104 additions & 0 deletions
104
community/bolt/src/test/java/org/neo4j/bolt/security/auth/AuthTokenDecoderTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,104 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.bolt.security.auth; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
|
|||
import java.util.Collections; | |||
import java.util.Map; | |||
|
|||
import org.neo4j.kernel.api.security.AuthToken; | |||
|
|||
import static org.neo4j.helpers.collection.MapUtil.map; | |||
|
|||
public abstract class AuthTokenDecoderTest | |||
{ | |||
protected abstract void testShouldDecodeAuthToken( Map<String,Object> authToken ) throws Exception; | |||
|
|||
protected abstract void testShouldFailToDecodeAuthToken( Map<String,Object> authToken, String expectedErrorMessage ) throws Exception; | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithStringCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.CREDENTIALS, "password" ) ); | |||
} | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithEmptyStringCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.CREDENTIALS, "" ) ); | |||
} | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithNullCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.CREDENTIALS, null ) ); | |||
} | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithStringNewCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.NEW_CREDENTIALS, "password" ) ); | |||
} | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithEmptyStringNewCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.NEW_CREDENTIALS, "" ) ); | |||
} | |||
|
|||
@Test | |||
void shouldDecodeAuthTokenWithNullNewCredentials() throws Exception | |||
{ | |||
testShouldDecodeAuthToken( authTokenMapWith( AuthToken.NEW_CREDENTIALS, null ) ); | |||
} | |||
|
|||
@Test | |||
void shouldFailToDecodeAuthTokenWithCredentialsOfUnsupportedTypes() throws Exception | |||
{ | |||
for ( Object value : valuesWithInvalidTypes ) | |||
{ | |||
testShouldFailToDecodeAuthToken( authTokenMapWith( AuthToken.CREDENTIALS, value ), | |||
"INIT message authentication token field '" + AuthToken.CREDENTIALS + "' should be a UTF-8 encoded string" ); | |||
} | |||
} | |||
|
|||
@Test | |||
void shouldFailToDecodeAuthTokenWithNewCredentialsOfUnsupportedType() throws Exception | |||
{ | |||
for ( Object value : valuesWithInvalidTypes ) | |||
{ | |||
testShouldFailToDecodeAuthToken( authTokenMapWith( AuthToken.NEW_CREDENTIALS, value ), | |||
"INIT message authentication token field '" + AuthToken.NEW_CREDENTIALS + "' should be a UTF-8 encoded string" ); | |||
} | |||
} | |||
|
|||
private static Map<String,Object> authTokenMapWith( String fieldName, Object fieldValue ) | |||
{ | |||
return map( AuthToken.PRINCIPAL, "neo4j", fieldName, fieldValue ); | |||
} | |||
|
|||
private static Object[] valuesWithInvalidTypes = { | |||
// This is not an exhaustive list | |||
new char[]{ 'p', 'a', 's', 's' }, | |||
Collections.emptyList(), | |||
Collections.emptyMap() | |||
}; | |||
} |
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
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