Skip to content

Commit

Permalink
Make test environment configurable (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
giarc3 authored Nov 6, 2019
1 parent 9e8ed3a commit dbee6f7
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 129 deletions.
3 changes: 0 additions & 3 deletions .cargo/config

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Cargo.lock
*.code-workspace
.metals/
tests/testkeys/*.pem
tests/testkeys/*.json
java/scala/src/test/resources/service-keys.conf
java/scala/src/test/resources/service-keys.conf.stage
java/scala/src/test/resources/service-keys.conf.local
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ cache:
before_cache:
- rm -rf /home/travis/.cargo/registry
rust:
- 1.36.0
- 1.38.0
branches:
only:
- master
before_install:
# key for integration tests
- openssl aes-256-cbc -K $encrypted_86f168e6939a_key -iv $encrypted_86f168e6939a_iv -in tests/testkeys/rsa_private.pem.enc -out tests/testkeys/rsa_private.pem -d
- openssl aes-256-cbc -K $encrypted_d5683c11b5e1_key -iv $encrypted_d5683c11b5e1_iv -in tests/testkeys/iak-dev.pem.enc -out tests/testkeys/iak-dev.pem -d
before_script:
- rustup component add rustfmt-preview
- cross --version || cargo install cross
Expand Down
2 changes: 1 addition & 1 deletion .travis_scripts/cross-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x

# If no special target provided, use default cargo arch for building and run all unit tests
if [ -z "$TARGET" ]; then
cargo t --verbose
IRONCORE_ENV=dev cargo t --verbose
cargo fmt -- --check
# Cross doesn't have support for iOS builds, so use cargo to add the target and compile for it
elif [ "$IOS" = 1 ]; then
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog

## 0.14.0 (Unreleased)

- [[#69](https://github.com/IronCoreLabs/ironoxide/pull/69)]
- Allows changing of IronCore environment at runtime.
- [[#64](https://github.com/IronCoreLabs/ironoxide/pull/64)]
- Adds need_rotation to `GroupCreateOpts`, allowing a group to be created with its private key marked for rotation
- Adds need_rotation to `GroupCreateOpts`, allowing a group to be created with its private key marked for rotation.

## 0.13.0

Expand Down
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ log = "~0.4"
protobuf = {version = "~2.8", features = ["with-bytes"]}

[dev-dependencies]
frank_jwt = "~3.1.1"
frank_jwt = "~3.1.2"
galvanic-assert = "~0.8"
uuid = { version = "~0.7.2", features = ["serde", "v4"] }
double = "~0.2.4"


[build-dependencies]
protobuf-codegen-pure = "~2.8"

[features]
senv = []
protobuf-codegen-pure = "~2.8"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you are not building a Rust application, you might be interested in one of th

- [ironoxide-java](https://github.com/IronCoreLabs/ironoxide-java) - Java bindings for ironoxide. Appropriate for all JVM langauges.
- [ironoxide-scala](https://github.com/IronCoreLabs/ironoxide-scala) - Scala wrappers around `ironoxide-java`.
- [ironode](https://github.com/IronCoreLabs/ironnode) - NodeJS implementation of IronCore's Privacy Platform.
- [ironnode](https://github.com/IronCoreLabs/ironnode) - NodeJS implementation of IronCore's Privacy Platform.
- [ironweb](https://github.com/IronCoreLabs/ironweb) - Javascript implementation of IronCore's Privacy Platform. Appropriate for all modern browsers.

All SDKs are intended to be compatible with one another.
Expand Down
10 changes: 6 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
extern crate protobuf_codegen_pure;
use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
use std::{
env,
fs::File,
io::{Read, Write},
path::Path,
};

fn main() {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR should exist");
Expand Down
21 changes: 14 additions & 7 deletions src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ pub mod group_api;
mod rest;
pub mod user_api;

#[cfg(feature = "senv")]
pub const OUR_REQUEST: IronCoreRequest =
IronCoreRequest::new("https://api-staging.ironcorelabs.com/api/1/");

#[cfg(not(feature = "senv"))]
pub const OUR_REQUEST: IronCoreRequest =
IronCoreRequest::new("https://api.ironcorelabs.com/api/1/");
lazy_static! {
pub static ref URL_STRING: String = match std::env::var("IRONCORE_ENV") {
Ok(url) => match url.to_lowercase().as_ref() {
"dev" => "https://api-dev1.ironcorelabs.com/api/1/",
"stage" => "https://api-staging.ironcorelabs.com/api/1/",
"prod" => "https://api.ironcorelabs.com/api/1/",
url_choice => url_choice,
}
.to_string(),
_ => "https://api.ironcorelabs.com/api/1/".to_string(),
};
pub static ref OUR_REQUEST: IronCoreRequest::<'static> =
IronCoreRequest::new(URL_STRING.as_str());
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum RequestErrorCode {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ impl<'a> HeaderIronCoreRequestSig<'a> {
}

///A struct which holds the basic info that will be needed for making requests to an ironcore service. Currently just the base_url.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Copy)]
pub struct IronCoreRequest<'a> {
base_url: &'a str,
}

impl Default for IronCoreRequest<'static> {
fn default() -> Self {
OUR_REQUEST
*OUR_REQUEST
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl UserOps for IronOxide {
jwt.try_into()?,
password.try_into()?,
user_create_opts.needs_rotation,
OUR_REQUEST,
*OUR_REQUEST,
))
}

Expand All @@ -178,7 +178,7 @@ impl UserOps for IronOxide {
password.try_into()?,
device_create_options.device_name,
&std::time::SystemTime::now().into(),
OUR_REQUEST,
*OUR_REQUEST,
))
}

Expand All @@ -189,7 +189,7 @@ impl UserOps for IronOxide {

fn user_verify(jwt: &str) -> Result<Option<UserResult>> {
let mut rt = Runtime::new().unwrap();
rt.block_on(user_api::user_verify(jwt.try_into()?, OUR_REQUEST))
rt.block_on(user_api::user_verify(jwt.try_into()?, *OUR_REQUEST))
}

fn user_get_public_key(&self, users: &[UserId]) -> Result<HashMap<UserId, PublicKey>> {
Expand Down
57 changes: 47 additions & 10 deletions tests/INTEGRATION-TESTS.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
Integration Testing
===================
# Integration Testing

Our integration tests require that we point to the IronCore staging environment. In order to swap that out at compile time we use a Rust feature flag to causes the SDK to point to stage. To prevent us from having to always pass `--features` when running our tests, we created an alias so that `cargo t` will automatically apply that feature flag. If you run `cargo test` you'll get failures that will hopefully clue you in that you need to use `cargo t` instead.
Our integration tests default to pointing to the IronCore environment, and will therefore need to be set up before use. However, unit tests can be run without prior setup.

Running *only* the unit tests (IronOxide users - this is what you want):
To run _only_ the unit tests (IronOxide users - this is what you want):

`cargo t --lib`

Running *only* the integration tests:
To run _only_ the integration tests:

`cargo t --test group_ops --test user_ops --test document_ops`

Running all the tests:
To run all the tests:

`cargo t`

#### Integration Tests
## Testing against IronCore Dev, Stage, or Prod Environments

Integration tests are run as part of a PR build on Travis. These keys are stored as a Travis secret.
Integration tests run against IronCore environments require some test keys and configuration files. Pre-generated keys and config files can be found in `tests/testkeys/`. _Currently only IronCore devs have access to these keys._ The following ironhide command will decrypt the developer test keys.

The integration test run against IronCore's staging environment and require some tests keys. These can be found in `tests/testkeys/rsa_private.pem.iron`. _Currently only IronCore devs have access to these keys._ The following ironhide command will decrypt the developer test keys.
`$ ironhide file:decrypt tests/testkeys/*.iron`

`$ ironhide file:decrypt rsa_private.pem.iron`
### Running the Tests

The environment you would like to test against is specified in the environment variable `IRONCORE_ENV`. This variable can be set to `dev`, `stage`, or `prod` to use the pre-generated keys and config files. To test against these, run one of the following:

- Development: `IRONCORE_ENV=dev cargo t`
- Staging: `IRONCORE_ENV=stage cargo t`
- Production: `IRONCORE_ENV=prod cargo t`

## Testing against a different environment

IronOxide tests can be run against any other environment, with proper setup. To do this, you must provide an Identity Assertion Key file, an IronCore Config file, and the URL you would like to test against. This will require you to create a project, segment, and Identity Assertion Key using the admin console interface.

### Identity Assertion Key File

An Identity Assertion Key file must be downloaded from the admin console interface immediately after creating a new Identity Assertion Key. It must be named `iak.pem` and placed in `./tests/testkeys/`.

### IronCore Config File

An IronCore Config file can be downloaded from the admin console on creation of the very first project. For subsequent projects, it will need to be created manually. The file is of the form:

```javascript
{
"projectId": YOUR_PROJECT_ID,
"segmentId": "YOUR_SEGMENT_ID",
"identityAssertionKeyId": YOUR_IDENTITY_ASSERION_KEY_ID
}
```

Note that case is significant for the key names.

This file must be named `ironcore-config.json` and placed in `./tests/testkeys/`.

### Environment URL

The URL of the environment you would like to test against is specified in the environment variable `IRONCORE_ENV`. To specify this when running the tests, run the following:

Manual URL: `IRONCORE_ENV={URL} cargo t`

where `{URL}` is the URL of the environment you want to test against.
Loading

0 comments on commit dbee6f7

Please sign in to comment.