Elasticsearch Securemock

Allows creating mocks in tests without having to grant dangerous permissions to all of your code.

License

License

Categories

Categories

Search Business Logic Libraries Elasticsearch
GroupId

GroupId

org.elasticsearch
ArtifactId

ArtifactId

securemock
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

Elasticsearch Securemock
Allows creating mocks in tests without having to grant dangerous permissions to all of your code.
Source Code Management

Source Code Management

https://github.com/elastic/securemock

Download securemock

How to add to project

<!-- https://jarcasting.com/artifacts/org.elasticsearch/securemock/ -->
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>securemock</artifactId>
    <version>1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.elasticsearch/securemock/
implementation 'org.elasticsearch:securemock:1.2'
// https://jarcasting.com/artifacts/org.elasticsearch/securemock/
implementation ("org.elasticsearch:securemock:1.2")
'org.elasticsearch:securemock:jar:1.2'
<dependency org="org.elasticsearch" name="securemock" rev="1.2">
  <artifact name="securemock" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.elasticsearch', module='securemock', version='1.2')
)
libraryDependencies += "org.elasticsearch" % "securemock" % "1.2"
[org.elasticsearch/securemock "1.2"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

securemock

Allows creating mocks in tests without having to grant dangerous permissions to all of your code.

This wraps the mockito api with AccessController blocks. No code changes are needed.

Instead of:

<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-core</artifactId>
  <version>1.9.5</version>
  <scope>test</scope>
</dependency>
...
grant {
  // give scary permission to all code just for tests
  permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
  permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
  permission java.lang.RuntimePermission "reflectionFactoryAccess";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

You can do:

<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>securemock</artifactId>
  <version>1.2</version>
  <scope>test</scope>
</dependency>
...
grant codeBase "/url/to/securemock.jar" {
  // only allow this jar used in tests to do this
  permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
  permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
  permission java.lang.RuntimePermission "reflectionFactoryAccess";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};
org.elasticsearch

elastic

Versions

Version
1.2
1.1
1.0