|
|
|
@ -393,7 +393,7 @@ public class JsonRpcHttpServiceLoginTest { |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), ethBlockNumber)) |
|
|
|
|
.isTrue(); |
|
|
|
|
// eth/accounts not permitted
|
|
|
|
|
// eth/accounts NOT permitted
|
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), ethAccounts)) |
|
|
|
@ -407,7 +407,7 @@ public class JsonRpcHttpServiceLoginTest { |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), web3Sha3)) |
|
|
|
|
.isTrue(); |
|
|
|
|
// no net permissions
|
|
|
|
|
// NO net permissions
|
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), netVersion)) |
|
|
|
@ -416,6 +416,66 @@ public class JsonRpcHttpServiceLoginTest { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void checkJsonRpcMethodsAvailableWithGoodCredentialsAndAllPermissions() |
|
|
|
|
throws IOException { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create(JSON, "{\"username\":\"adminuser\",\"password\":\"pegasys\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build(); |
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
assertThat(resp.message()).isEqualTo("OK"); |
|
|
|
|
assertThat(resp.body().contentType()).isNotNull(); |
|
|
|
|
assertThat(resp.body().contentType().type()).isEqualTo("application"); |
|
|
|
|
assertThat(resp.body().contentType().subtype()).isEqualTo("json"); |
|
|
|
|
final String bodyString = resp.body().string(); |
|
|
|
|
assertThat(bodyString).isNotNull(); |
|
|
|
|
assertThat(bodyString).isNotBlank(); |
|
|
|
|
|
|
|
|
|
final JsonObject respBody = new JsonObject(bodyString); |
|
|
|
|
final String token = respBody.getString("token"); |
|
|
|
|
assertThat(token).isNotNull(); |
|
|
|
|
|
|
|
|
|
final JsonRpcMethod ethAccounts = new EthAccounts(); |
|
|
|
|
final JsonRpcMethod netVersion = new NetVersion(Optional.of(BigInteger.valueOf(123))); |
|
|
|
|
final JsonRpcMethod ethBlockNumber = new EthBlockNumber(blockchainQueries); |
|
|
|
|
final JsonRpcMethod web3Sha3 = new Web3Sha3(); |
|
|
|
|
final JsonRpcMethod web3ClientVersion = new Web3ClientVersion("777"); |
|
|
|
|
|
|
|
|
|
// adminuser has *:* permissions so everything should be allowed
|
|
|
|
|
jwtAuth.authenticate( |
|
|
|
|
new JsonObject().put("jwt", token), |
|
|
|
|
(r) -> { |
|
|
|
|
assertThat(r.succeeded()).isTrue(); |
|
|
|
|
final User user = r.result(); |
|
|
|
|
// single eth/blockNumber method permitted
|
|
|
|
|
Assertions.assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), ethBlockNumber)) |
|
|
|
|
.isTrue(); |
|
|
|
|
// eth/accounts IS permitted
|
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), ethAccounts)) |
|
|
|
|
.isTrue(); |
|
|
|
|
// allowed by *:*
|
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), web3ClientVersion)) |
|
|
|
|
.isTrue(); |
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), web3Sha3)) |
|
|
|
|
.isTrue(); |
|
|
|
|
// YES net permissions
|
|
|
|
|
assertThat( |
|
|
|
|
AuthenticationUtils.isPermitted( |
|
|
|
|
service.authenticationService, Optional.of(user), netVersion)) |
|
|
|
|
.isTrue(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void checkPermissionsWithEmptyUser() { |
|
|
|
|
final JsonRpcMethod ethAccounts = new EthAccounts(); |
|
|
|
|