mirror of https://github.com/hyperledger/besu
Allow use of privacy public key in the credentials file (#196)
Signed-off-by: Jason Frame <jasonwframe@gmail.com>pull/205/head
parent
a449e81b2d
commit
c1ddab52fb
@ -0,0 +1,21 @@ |
|||||||
|
[Users.userA] |
||||||
|
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
||||||
|
groups = ["admin"] |
||||||
|
# This line is invalid - should be an array |
||||||
|
permissions = "eth:*" |
||||||
|
roles = ["net"] |
||||||
|
|
||||||
|
[Users.userB] |
||||||
|
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
||||||
|
groups = ["admin"] |
||||||
|
permissions = ["eth:*", "perm:*"] |
||||||
|
roles = ["net"] |
||||||
|
|
||||||
|
[Groups.admins] |
||||||
|
roles = ["admin"] |
||||||
|
|
||||||
|
[Roles.admin] |
||||||
|
permissions = ["admin:*"] |
||||||
|
|
||||||
|
[Roles.net] |
||||||
|
permissions = ["net:*"] |
@ -0,0 +1,22 @@ |
|||||||
|
[Users.userA] |
||||||
|
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
||||||
|
groups = ["admin"] |
||||||
|
permissions = ["eth:*", "perm:*"] |
||||||
|
roles = ["net"] |
||||||
|
# This line is invalid - should be a non-empty value |
||||||
|
privacyPublicKey = "" |
||||||
|
|
||||||
|
[Users.userB] |
||||||
|
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
||||||
|
groups = ["admin"] |
||||||
|
permissions = ["eth:*", "perm:*"] |
||||||
|
roles = ["net"] |
||||||
|
|
||||||
|
[Groups.admins] |
||||||
|
roles = ["admin"] |
||||||
|
|
||||||
|
[Roles.admin] |
||||||
|
permissions = ["admin:*"] |
||||||
|
|
||||||
|
[Roles.net] |
||||||
|
permissions = ["net:*"] |
@ -0,0 +1,63 @@ |
|||||||
|
/* |
||||||
|
* Copyright ConsenSys AG. |
||||||
|
* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
package org.hyperledger.besu.ethereum.api.jsonrpc.authentication; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
import static org.assertj.core.util.Lists.list; |
||||||
|
|
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
import io.vertx.core.json.JsonArray; |
||||||
|
import io.vertx.core.json.JsonObject; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class TomlUserTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void createsPrincipleWithAllValues() { |
||||||
|
final TomlUser tomlUser = |
||||||
|
new TomlUser( |
||||||
|
"user", |
||||||
|
"password", |
||||||
|
list("admin"), |
||||||
|
list("eth:*", "perm:*"), |
||||||
|
list("net"), |
||||||
|
Optional.of("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=")); |
||||||
|
|
||||||
|
final JsonObject principal = tomlUser.principal(); |
||||||
|
assertThat(principal.getString("username")).isEqualTo("user"); |
||||||
|
assertThat(principal.getString("password")).isEqualTo("password"); |
||||||
|
assertThat(principal.getJsonArray("groups")).isEqualTo(new JsonArray(list("admin"))); |
||||||
|
assertThat(principal.getJsonArray("permissions")) |
||||||
|
.isEqualTo(new JsonArray(list("eth:*", "perm:*"))); |
||||||
|
assertThat(principal.getJsonArray("roles")).isEqualTo(new JsonArray(list("net"))); |
||||||
|
assertThat(principal.getString("privacyPublicKey")) |
||||||
|
.isEqualTo("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void createsPrincipleWithOnlyRequiredValues() { |
||||||
|
final TomlUser tomlUser = |
||||||
|
new TomlUser("user", "password", list(), list(), list(), Optional.empty()); |
||||||
|
|
||||||
|
final JsonObject principal = tomlUser.principal(); |
||||||
|
assertThat(principal.getString("username")).isEqualTo("user"); |
||||||
|
assertThat(principal.getString("password")).isEqualTo("password"); |
||||||
|
assertThat(principal.getJsonArray("groups")).isEqualTo(new JsonArray()); |
||||||
|
assertThat(principal.getJsonArray("permissions")).isEqualTo(new JsonArray()); |
||||||
|
assertThat(principal.getJsonArray("roles")).isEqualTo(new JsonArray()); |
||||||
|
assertThat(principal.containsKey("privacyPublicKey")).isFalse(); |
||||||
|
} |
||||||
|
} |
@ -1,3 +1,4 @@ |
|||||||
[Users.user] |
[Users.user] |
||||||
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" |
||||||
permissions = ["fakePermission","eth:blockNumber","eth:subscribe","web3:*"] |
permissions = ["fakePermission","eth:blockNumber","eth:subscribe","web3:*"] |
||||||
|
privacyPublicKey = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=" |
||||||
|
@ -1 +1 @@ |
|||||||
Subproject commit cfbcd15f91d4d6e1785d9cae5c5c37f47e8bad46 |
Subproject commit 0327d9f76ce2a292a99e7a9dfc93627368ce589e |
Loading…
Reference in new issue