Giter Club home page Giter Club logo

te-performer-app's Introduction

Overview

This node.js module is meant to provide three things:

  1. A library of models (UserProfile, Team, Schedule, Report, Problem) which can be used to easily interact with the createbetterreasoning T&E API.
  2. A series of mocha tests that report the state of the API.
  3. A series of mocha tests showing how to use the provided models to play out some common workflow patterns typically used by performers.

Models Implemented

  • UserProfile
  • Team
  • Schedule
  • Report
  • Problem
  • UserCommitment

Requirements

  • Node: v7.10 up to v8.8.1 (note version 8.9.1 is not supported)
  • Npm: v3.10.x up to v5.5.1
  • The tests are confirmed to work using node v8.5.0 (npm v5.3.0)

Install

First make sure you've installed Node.js, then run:
npm install -g mocha
git clone https://github.com/CREATE-TE/cos_app
cd path/to/repo/
npm install

Usage

All models can be imported from the 'src/models' directory. For example:
const { UserProfile } = require('./src/models');

Models provide functions used for easily interacting with the API.
All models implement the same functions:

// Use query() to fetch a list of records 
UserProfile.query({byConditionLabel: 'bard'}) // Returns a promise resolving to an array of UserProfile instances.
  .then(userModels => {       
    // do something using userModels array
  })
;
// Use findRecord() to fetch a single record by id
UserProfile.findRecord('12345abcde') // Returns a promise resolving to a UserProfile instance.
  .then(userModel => {
    // do something with userModel here
  })
  .catch(e => {
    // handle user not found
  })
;
// Use get() to read the model's data
let userName = userModel.get('userName');
console.log(userName);  
// Use set(), and save() to save the state of the model back to the API
userModel.set('lastActive.bard', Date.now()); // setting last active for bard
userModel.set('trainedOn.bard', true);        // setting trained on bard to true

userModel.save();  // Saves lastActive and trainedOn states to the API

Prepare your Testing Environment

Perform the following sequence of steps to ensure that all endpoints are available for testing:

  1. Successfully log into either https://www.createbetterreasoning.com or https://dev-www.createbetterreasoning.com using valid user credentials in your browser.
  2. Open your browser's development console and locate the cookie provided for your current session. The cookie should appear similar to the following JSESSIONID=F521D63500CD3F7C38B5990F462E21D8.
  3. Copy and paste the above cookie value to the first line of the file token.txt located at the root of this project.
  4. Proceed to run any tests described below.

API Authentication

The API is not accessible unless you authenticate prior to making requests. To successfully authenticate, first create a local settings file in the config directory for the environment you wish to run (e.g. config/local-dev.json). Next, place your Performer username and password that was provided to you in the local settings file (e.g. {"user":"", "pass":""} ). You may receive a 401 error response if this step is not performed.

Running the Tests

To run unit tests for all API endpoints on dev-www.createbetterreasoning.com:
npm run dev-api

For running tests against the API endpoints on www.createbetterreasoning.com:
npm run prod-api

Stress Testing the API

To begin stress testing the system, there are two scripts that first need to be ran. The first will take as input a CSV file containing the tasks to execute against the API. (See /stress_test/mock_input.csv for an example). That file is then used to generate a task distribution, where each task is assigned a time delta according to a Poisson distribution.
The second script will take as input the generated CSV of the first script and spawn a multi-threaded cluster of nodes which will execute tasks concurrently to simulate real user activity. Each node (or thread) targets a specific performer system.

  1. First Generate the Poisson distribution CSV file:
    npm run gen-stress-csv /path/to/input.csv
    Optionally, specify the total time interval in seconds that the events should be distributed across:
    npm run gen-stress-csv -- --seconds 90 /path/to/input.csv
  2. Second Run the stress test. Set the TASKS_FILE to the path of the output file from the first script:
    TASKS_FILE=/path/to/events_distribution.csv npm run dev-stress

Generating test reports:

You can generate the test reports as a CSV document by running:
npm run prod-generate-csv
npm run dev-generate-csv
npm run cos-generate-csv

Running the Workflows

The workflows require additional python libraries to execute T&E's validation script.
It is recommended the following steps are done prior to running workflow steps:

  1. install virtualenv using your OS package manager (ex. apt-get install virtualenv)
  2. virtualenv tenv (setup a virtual environment for python 2.7)
  3. source tenv/bin/activate (enter python virtual env)
  4. pip install -r requirements.txt (install all dependencies for T&E's validation script)
  5. Now you should be able to run the workflow tests

npm run dev-workflows
npm run prod-workflows
npm run cos-workflows

te-performer-app's People

Contributors

abrinckm avatar swyngaard avatar ian-taylor avatar

Watchers

James Cloos avatar  avatar  avatar

te-performer-app's Issues

Content Type Header Missing (CRAFT)

Timothy Wright wrote:

The ZAP scanner has discovered an instance in which content is served without a content type. Examples may be found at, though not limited to, the following URLs:

It is important that all served content have an appropriate content type in order to prevent attacks based on MIME-type confusion. Also, note the importance of setting the HTTP header parameter

X-Content-Type-Options: nosniff

Doing this will signal browsers to ignore content for which they do not have a content type.

For more detail on this finding, please see the ZAP report at

https://baldin.crc.nd.edu/CRC-Restricted/ScanResults/CRAFT/2017/ZAP_CRAFT_Dev_11-17-17.html

For the CRC's recommended Apache configuration, please see

https://redmine.crc.nd.edu/redmine/projects/bestpractice/wiki/General_Security_Approach#Suggested-General-Apache-Configuration

Setup a temporary disposal CAS VM for the security scan on 11/16

Worked with Matt to clone the CAS VM and re-configured ember-craft and osf-craft to use this temporary server until after Tim and Swapna have completed their security scans. We don't want them thrashing the real CAS.

Temporary CAS is at cas-scan.craftproject.org

Investigate server-side OAuth solution

We would prefer functionality similar to what the Girder backend provides for the Whole Tale project. We may need to consult with Kacper on how this was achieved in the Whole Tale project

Cross-Domain JavaScript Source File Inclusion (CRAFT)

Timothy Wright wrote:

ZAP has discovered links to remote JavaScript resources. Linking to JavaScript outside of a site's domain is dangerous, because such JavaScript is not under the site's control and could be tampered with or changed in a deleterious manner.

An example link to the cross-domain files would be

https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.min.js

It is recommended that, whenever feasible, JavaScript be served from a given web server's domain.

For additional detail, please review the ZAP report at:

https://baldin.crc.nd.edu/CRC-Restricted/ScanResults/CRAFT/2017/ZAP_CRAFT_Dev_11-17-17.html

Write Health Dashboard

Also, as we were discussing this, we thought a nice extension to this COS app would be to provide a API Health Dashboard Web interface. which would expose Sample App test suite as a CREATE Web GUI Health dashboard that shows the status of the API at any point in time. This would have the following:


• A backend Web server API that parses test app info to provide data for front-end consumption (JSON spec). The information could be refreshed every 60 seconds.

• A front end GUI could provide a card-like interface showing the status (green, orange, red) of each section (API resource) of the API and then have click throughs to see detailed information. 

• Each click through could show the test suite output for each API resource e.g. using a terminal style GUI output.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.