2015-07-20 00:09:47 -07:00
'use strict' ;
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
2019-05-03 14:00:21 -07:00
/* global xit:false */
2015-07-20 00:09:47 -07:00
2019-04-17 13:33:10 +02:00
var appdb = require ( '../../appdb.js' ) ,
2015-07-20 00:09:47 -07:00
apps = require ( '../../apps.js' ) ,
assert = require ( 'assert' ) ,
async = require ( 'async' ) ,
child _process = require ( 'child_process' ) ,
2016-06-03 14:47:06 +02:00
clients = require ( '../../clients.js' ) ,
2015-07-20 00:09:47 -07:00
constants = require ( '../../constants.js' ) ,
database = require ( '../../database.js' ) ,
2015-10-19 11:24:21 -07:00
docker = require ( '../../docker.js' ) . connection ,
2015-07-20 00:09:47 -07:00
expect = require ( 'expect.js' ) ,
fs = require ( 'fs' ) ,
2019-04-18 13:11:56 +02:00
hat = require ( '../../hat.js' ) ,
2015-07-20 00:09:47 -07:00
hock = require ( 'hock' ) ,
http = require ( 'http' ) ,
https = require ( 'https' ) ,
2016-05-23 20:17:11 -07:00
ldap = require ( '../../ldap.js' ) ,
2015-07-20 00:09:47 -07:00
net = require ( 'net' ) ,
nock = require ( 'nock' ) ,
2018-02-05 17:28:30 +01:00
path = require ( 'path' ) ,
2015-07-20 00:09:47 -07:00
paths = require ( '../../paths.js' ) ,
2018-10-29 11:49:37 -07:00
platform = require ( '../../platform.js' ) ,
2015-07-20 00:09:47 -07:00
safe = require ( 'safetydance' ) ,
server = require ( '../../server.js' ) ,
2015-07-23 12:59:47 +02:00
settings = require ( '../../settings.js' ) ,
2019-05-03 14:00:21 -07:00
settingsdb = require ( '../../settingsdb.js' ) ,
2016-05-23 20:17:11 -07:00
superagent = require ( 'superagent' ) ,
2016-01-29 16:27:35 +01:00
taskmanager = require ( '../../taskmanager.js' ) ,
2019-04-18 13:11:56 +02:00
tokendb = require ( '../../tokendb.js' ) ,
2015-07-20 00:09:47 -07:00
url = require ( 'url' ) ,
2017-08-13 17:44:31 -07:00
uuid = require ( 'uuid' ) ,
2015-07-20 00:09:47 -07:00
_ = require ( 'underscore' ) ;
2019-07-25 15:43:51 -07:00
var SERVER _URL = 'http://localhost:' + constants . PORT ;
2015-07-20 00:09:47 -07:00
2015-09-29 13:51:50 -07:00
// Test image information
var TEST _IMAGE _REPO = 'cloudron/test' ;
2019-04-18 13:11:56 +02:00
var TEST _IMAGE _TAG = '25.15.2' ;
2016-01-21 14:59:24 -08:00
var TEST _IMAGE = TEST _IMAGE _REPO + ':' + TEST _IMAGE _TAG ;
2018-02-02 14:06:01 +01:00
2018-02-01 18:04:35 +01:00
const DOMAIN _0 = {
domain : 'example-apps-test.com' ,
2019-04-17 13:33:10 +02:00
adminFqdn : 'my.example-apps-test.com' ,
2018-02-01 18:04:35 +01:00
zoneName : 'example-apps-test.com' ,
config : { } ,
provider : 'noop' ,
fallbackCertificate : null ,
tlsConfig : { provider : 'fallback' }
} ;
2015-09-29 13:51:50 -07:00
2015-07-20 00:09:47 -07:00
var APP _STORE _ID = 'test' , APP _ID ;
var APP _LOCATION = 'appslocation' ;
var APP _LOCATION _2 = 'appslocationtwo' ;
var APP _LOCATION _NEW = 'appslocationnew' ;
2015-10-16 20:01:45 +02:00
2015-07-20 00:09:47 -07:00
var APP _MANIFEST = JSON . parse ( fs . readFileSync ( _ _dirname + '/../../../../test-app/CloudronManifest.json' , 'utf8' ) ) ;
2016-01-21 14:59:24 -08:00
APP _MANIFEST . dockerImage = TEST _IMAGE ;
2015-10-16 20:01:45 +02:00
2018-02-05 22:17:16 +01:00
const USERNAME = 'superadmin' ;
const PASSWORD = 'Foobar?1337' ;
const EMAIL = 'admin@me.com' ;
2018-02-02 14:06:01 +01:00
const USER _1 _APPSTORE _TOKEN = 'appstoretoken' ;
2018-02-05 22:17:16 +01:00
const USERNAME _1 = 'user' ;
const EMAIL _1 = 'user@me.com' ;
var user _1 _id = null ;
// authentication token
var token = null ;
2015-07-20 00:09:47 -07:00
var token _1 = null ;
function startDockerProxy ( interceptor , callback ) {
assert . strictEqual ( typeof interceptor , 'function' ) ;
return http . createServer ( function ( req , res ) {
if ( interceptor ( req , res ) ) return ;
// rejectUnauthorized should not be required but it doesn't work without it
var options = _ . extend ( { } , docker . options , { method : req . method , path : req . url , headers : req . headers , rejectUnauthorized : false } ) ;
delete options . protocol ; // https module doesn't like this key
var proto = docker . options . protocol === 'https' ? https : http ;
var dockerRequest = proto . request ( options , function ( dockerResponse ) {
res . writeHead ( dockerResponse . statusCode , dockerResponse . headers ) ;
dockerResponse . on ( 'error' , console . error ) ;
dockerResponse . pipe ( res , { end : true } ) ;
} ) ;
req . on ( 'error' , console . error ) ;
if ( ! req . readable ) {
dockerRequest . end ( ) ;
} else {
req . pipe ( dockerRequest , { end : true } ) ;
}
} ) . listen ( 5687 , callback ) ;
}
2016-06-16 14:43:07 -05:00
function checkAddons ( appEntry , done ) {
2016-06-17 11:12:20 -05:00
async . retry ( { times : 15 , interval : 3000 } , function ( callback ) {
// this was previously written with superagent but it was getting sporadic EPIPE
var req = http . get ( { hostname : 'localhost' , port : appEntry . httpPort , path : '/check_addons?username=' + USERNAME + '&password=' + PASSWORD } ) ;
req . on ( 'error' , callback ) ;
req . on ( 'response' , function ( res ) {
2016-06-16 15:09:46 -05:00
if ( res . statusCode !== 200 ) return callback ( 'app returned non-200 status : ' + res . statusCode ) ;
2016-06-16 14:43:07 -05:00
2016-06-17 11:12:20 -05:00
var d = '' ;
res . on ( 'data' , function ( chunk ) { d += chunk . toString ( 'utf8' ) ; } ) ;
res . on ( 'end' , function ( ) {
var body = JSON . parse ( d ) ;
2016-06-16 14:43:07 -05:00
2016-06-17 11:12:20 -05:00
delete body . recvmail ; // unclear why dovecot mail delivery won't work
delete body . stdenv ; // cannot access APP_ORIGIN
2018-02-05 22:17:16 +01:00
delete body . email ; // sieve will fail not sure why yet
2019-04-18 13:11:56 +02:00
delete body . docker ; // TODO fix this for some reason we cannot connect to the docker proxy on port 3003
2016-06-17 11:12:20 -05:00
for ( var key in body ) {
2019-04-24 14:23:19 -07:00
if ( body [ key ] !== 'OK' ) {
console . log ( 'Not done yet: ' + JSON . stringify ( body ) ) ;
return callback ( 'Not done yet: ' + JSON . stringify ( body ) ) ;
}
2016-06-17 11:12:20 -05:00
}
2016-06-16 14:43:07 -05:00
2016-06-17 11:12:20 -05:00
callback ( ) ;
} ) ;
2016-06-16 14:43:07 -05:00
} ) ;
2016-06-17 11:12:20 -05:00
req . end ( ) ;
2016-06-16 14:43:07 -05:00
} , done ) ;
}
2016-06-20 22:59:47 -05:00
function checkRedis ( containerId , done ) {
var redisIp , exportedRedisPort ;
docker . getContainer ( containerId ) . inspect ( function ( error , data ) {
expect ( error ) . to . not . be . ok ( ) ;
expect ( data ) . to . be . ok ( ) ;
redisIp = safe . query ( data , 'NetworkSettings.Networks.cloudron.IPAddress' ) ;
expect ( redisIp ) . to . be . ok ( ) ;
exportedRedisPort = safe . query ( data , 'NetworkSettings.Ports.6379/tcp' ) ;
expect ( exportedRedisPort ) . to . be ( null ) ;
done ( ) ;
} ) ;
}
2017-02-06 21:53:29 -08:00
var dockerProxy ;
var imageDeleted ;
var imageCreated ;
2019-04-17 13:33:10 +02:00
function waitForSetup ( done ) {
async . retry ( { times : 5 , interval : 4000 } , function ( retryCallback ) {
superagent . get ( SERVER _URL + '/api/v1/cloudron/status' )
. end ( function ( error , result ) {
if ( ! result || result . statusCode !== 200 ) return retryCallback ( new Error ( 'Bad result' ) ) ;
if ( ! result . body . setup . active && result . body . setup . errorMessage === '' && result . body . adminFqdn ) return retryCallback ( ) ;
retryCallback ( new Error ( 'Not done yet: ' + JSON . stringify ( result . body ) ) ) ;
} ) ;
} , done ) ;
}
2017-02-06 21:53:29 -08:00
function startBox ( done ) {
2019-04-18 13:11:56 +02:00
console . log ( 'Starting box code...' ) ;
2017-02-06 21:53:29 -08:00
imageDeleted = false ;
imageCreated = false ;
process . env . TEST _CREATE _INFRA = 1 ;
safe . fs . unlinkSync ( paths . INFRA _VERSION _FILE ) ;
async . series ( [
// first clear, then start server. otherwise, taskmanager spins up tasks for obsolete appIds
database . initialize ,
database . _clear ,
2018-02-01 18:04:35 +01:00
server . start ,
2017-02-06 21:53:29 -08:00
ldap . start ,
2019-08-05 07:01:12 -07:00
settings . _setApiServerOrigin . bind ( null , 'http://localhost:6060' ) ,
2017-02-06 21:53:29 -08:00
function ( callback ) {
2019-04-17 13:33:10 +02:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/setup' )
. send ( { dnsConfig : DOMAIN _0 } )
2018-04-30 21:41:09 -07:00
. end ( function ( error , result ) {
expect ( result ) . to . be . ok ( ) ;
expect ( result . statusCode ) . to . eql ( 200 ) ;
2017-02-06 21:53:29 -08:00
2019-04-17 13:33:10 +02:00
waitForSetup ( callback ) ;
2018-04-30 21:41:09 -07:00
} ) ;
2018-02-01 18:04:35 +01:00
} ,
function ( callback ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/cloudron/activate' )
2018-04-30 21:41:09 -07:00
. send ( { username : USERNAME , password : PASSWORD , email : EMAIL } )
. end ( function ( error , result ) {
expect ( result ) . to . be . ok ( ) ;
expect ( result . statusCode ) . to . eql ( 201 ) ;
2017-02-06 21:53:29 -08:00
2018-04-30 21:41:09 -07:00
// stash for further use
token = result . body . token ;
2016-01-29 14:30:40 +01:00
2018-04-30 21:41:09 -07:00
callback ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ,
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
function ( callback ) {
superagent . post ( SERVER _URL + '/api/v1/users' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { username : USERNAME _1 , email : EMAIL _1 , invite : false } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 201 ) ;
2015-10-16 20:01:45 +02:00
2018-04-30 21:41:09 -07:00
user _1 _id = res . body . id ;
2019-04-18 13:11:56 +02:00
token _1 = hat ( 8 * 32 ) ;
2016-12-13 11:31:14 -08:00
2019-04-18 13:11:56 +02:00
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
2019-04-24 15:39:47 -07:00
tokendb . add ( { id : 'tid-1' , accessToken : token _1 , identifier : user _1 _id , clientId : 'cid-sdk' , expires : Date . now ( ) + 1000000 , scope : 'apps' , name : '' } , callback ) ; // cid-sdk means we don't need to send password
2018-04-30 21:41:09 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ,
2015-10-13 10:03:50 +02:00
2017-02-06 21:53:29 -08:00
function ( callback ) {
dockerProxy = startDockerProxy ( function interceptor ( req , res ) {
if ( req . method === 'POST' && req . url === '/images/create?fromImage=' + encodeURIComponent ( TEST _IMAGE _REPO ) + '&tag=' + TEST _IMAGE _TAG ) {
imageCreated = true ;
res . writeHead ( 200 ) ;
res . end ( ) ;
return true ;
} else if ( req . method === 'DELETE' && req . url === '/images/' + TEST _IMAGE + '?force=false&noprune=false' ) {
imageDeleted = true ;
res . writeHead ( 200 ) ;
res . end ( ) ;
return true ;
}
return false ;
} , callback ) ;
2018-10-29 11:49:37 -07:00
} ,
2017-02-06 21:53:29 -08:00
2018-10-29 11:49:37 -07:00
function ( callback ) {
2019-04-18 13:11:56 +02:00
process . stdout . write ( 'Waiting for platform to be ready...' ) ;
async . retry ( { times : 500 , interval : 1000 } , function ( retryCallback ) {
2018-10-29 11:49:37 -07:00
if ( platform . _isReady ) return retryCallback ( ) ;
2019-04-18 13:11:56 +02:00
process . stdout . write ( '.' ) ;
2018-10-29 11:49:37 -07:00
retryCallback ( 'Platform not ready yet' ) ;
2019-04-18 13:11:56 +02:00
} , function ( error ) {
if ( error ) return callback ( error ) ;
console . log ( ) ;
2019-08-05 07:01:12 -07:00
console . log ( 'Platform is ready' ) ;
2019-04-18 13:11:56 +02:00
callback ( ) ;
} ) ;
2018-10-29 11:49:37 -07:00
}
] , done ) ;
2017-02-06 21:53:29 -08:00
}
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
function stopBox ( done ) {
2019-04-18 13:11:56 +02:00
console . log ( 'Stopping box code...' ) ;
2017-02-06 21:53:29 -08:00
delete process . env . TEST _CREATE _INFRA ;
2019-04-18 13:11:56 +02:00
child _process . execSync ( 'docker ps -qa --filter \'network=cloudron\' | xargs --no-run-if-empty docker rm -f' ) ;
2017-02-06 21:53:29 -08:00
// db is not cleaned up here since it's too late to call it after server.stop. if called before server.stop taskmanager apptasks are unhappy :/
async . series ( [
2019-04-18 13:11:56 +02:00
dockerProxy . close . bind ( dockerProxy ) ,
2019-03-08 19:09:34 -08:00
taskmanager . _stopPendingTasks ,
taskmanager . _waitForPendingTasks ,
2017-02-06 21:53:29 -08:00
appdb . _clear ,
server . stop ,
2019-07-26 10:49:29 -07:00
ldap . stop
2017-02-06 21:53:29 -08:00
] , done ) ;
}
2016-01-29 16:27:35 +01:00
2017-02-06 21:53:29 -08:00
describe ( 'App API' , function ( ) {
before ( startBox ) ;
after ( stopBox ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - missing manifest' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'appStoreId or manifest is required' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - null manifest' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : null } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'appStoreId or manifest is required' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - bad manifest format' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : 'epic' } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'manifest must be an object' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - empty appStoreId format' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : null , appStoreId : '' } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'appStoreId or manifest is required' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2018-04-30 21:41:09 -07:00
it ( 'app install fails - invalid json' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( 'garbage' )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2018-02-01 18:04:35 +01:00
it ( 'app install fails - missing domain' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : 'some' , accessRestriction : null } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'domain is required' ) ;
done ( ) ;
} ) ;
2018-02-01 18:04:35 +01:00
} ) ;
it ( 'app install fails - non-existing domain' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : 'some' , accessRestriction : null , domain : 'doesnotexist.com' } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 404 ) ;
expect ( res . body . message ) . to . eql ( 'No such domain' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - invalid location type' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : 42 , accessRestriction : null , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
expect ( res . body . message ) . to . eql ( 'location is required' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - reserved admin location' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : 'my' , accessRestriction : null , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
2018-08-31 14:06:06 -07:00
expect ( res . body . message ) . to . contain ( 'my is reserved' ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2019-06-09 18:16:14 -07:00
it ( 'app install fails - reserved smtp location' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-06-09 18:16:14 -07:00
. send ( { manifest : APP _MANIFEST , location : constants . SMTP _LOCATION , accessRestriction : null , domain : DOMAIN _0 . domain } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
2019-06-09 18:16:14 -07:00
expect ( res . body . message ) . to . contain ( constants . SMTP _LOCATION + ' is reserved' ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - portBindings must be object' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION , portBindings : 23 , accessRestriction : null , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
2018-08-31 14:06:06 -07:00
expect ( res . body . message ) . to . contain ( 'portBindings must be an object' ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - accessRestriction is required' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION , portBindings : { } , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
2018-08-31 14:06:06 -07:00
expect ( res . body . message ) . to . contain ( 'accessRestriction is required' ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-05-23 20:17:11 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails - accessRestriction type is wrong' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION , portBindings : { } , accessRestriction : '' , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
2018-08-31 14:06:06 -07:00
expect ( res . body . message ) . to . contain ( 'accessRestriction is required' ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-05-23 17:34:25 -07:00
2019-04-18 13:11:56 +02:00
it ( 'app install fails for non admin' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token _1 } )
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION , portBindings : null , accessRestriction : null , domain : DOMAIN _0 . domain } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 403 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails because manifest download fails' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake = nock ( settings . apiServerOrigin ( ) ) . get ( '/api/v1/apps/test' ) . reply ( 404 , { } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { appStoreId : APP _STORE _ID , location : APP _LOCATION , portBindings : null , domain : DOMAIN _0 . domain , accessRestriction : { users : [ 'someuser' ] , groups : [ ] } } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 404 ) ;
expect ( fake . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-04-18 18:12:56 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails due to purchase failure' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake1 = nock ( settings . apiServerOrigin ( ) ) . get ( '/api/v1/apps/test' ) . reply ( 200 , { manifest : APP _MANIFEST } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { appStoreId : APP _STORE _ID , location : APP _LOCATION , domain : DOMAIN _0 . domain , portBindings : null , accessRestriction : null } )
. end ( function ( err , res ) {
2019-05-06 15:00:22 -07:00
expect ( res . statusCode ) . to . equal ( 424 ) ;
2018-04-30 21:41:09 -07:00
expect ( fake1 . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install succeeds with purchase' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake2 = nock ( settings . apiServerOrigin ( ) ) . get ( '/api/v1/apps/' + APP _STORE _ID ) . reply ( 200 , { manifest : APP _MANIFEST } ) ;
var fake3 = nock ( settings . apiServerOrigin ( ) ) . post ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps' ) >= 0 ; } , ( body ) => body . appstoreId === APP _STORE _ID && body . manifestId === APP _MANIFEST . id && body . appId ) . reply ( 201 , { } ) ;
2018-02-02 14:06:01 +01:00
2019-05-03 16:27:47 -07:00
settingsdb . set ( settings . CLOUDRON _TOKEN _KEY , USER _1 _APPSTORE _TOKEN , function ( error ) {
2018-02-02 14:06:01 +01:00
if ( error ) return done ( error ) ;
2015-07-20 00:09:47 -07:00
2019-05-03 16:27:47 -07:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
. query ( { access _token : token } )
. send ( { appStoreId : APP _STORE _ID , location : APP _LOCATION , domain : DOMAIN _0 . domain , portBindings : null , accessRestriction : { users : [ 'someuser' ] , groups : [ ] } } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 202 ) ;
expect ( res . body . id ) . to . be . a ( 'string' ) ;
APP _ID = res . body . id ;
expect ( fake2 . isDone ( ) ) . to . be . ok ( ) ;
expect ( fake3 . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install fails because of conflicting location' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION , domain : DOMAIN _0 . domain , portBindings : null , accessRestriction : null } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 409 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can get app status' , function ( done ) {
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 200 ) ;
expect ( res . body . id ) . to . eql ( APP _ID ) ;
expect ( res . body . installationState ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'cannot get invalid app status' , function ( done ) {
superagent . get ( SERVER _URL + '/api/v1/apps/kubachi' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 404 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-01-29 17:24:18 +01:00
2017-02-06 21:53:29 -08:00
it ( 'can get all apps' , function ( done ) {
superagent . get ( SERVER _URL + '/api/v1/apps' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 200 ) ;
expect ( res . body . apps ) . to . be . an ( 'array' ) ;
expect ( res . body . apps [ 0 ] . id ) . to . eql ( APP _ID ) ;
expect ( res . body . apps [ 0 ] . installationState ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-01-29 17:24:18 +01:00
2019-04-18 13:11:56 +02:00
it ( 'non admin cannot see the app due to accessRestriction' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . get ( SERVER _URL + '/api/v1/apps' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token _1 } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 200 ) ;
expect ( res . body . apps ) . to . be . an ( 'array' ) ;
expect ( res . body . apps . length ) . to . equal ( 0 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'cannot uninstall invalid app' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/whatever/uninstall' )
. query ( { access _token : token } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 404 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2019-04-18 13:11:56 +02:00
it ( 'non admin cannot uninstall app' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/uninstall' )
. query ( { access _token : token _1 } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 403 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-05-23 20:17:11 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can uninstall app' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake1 = nock ( settings . apiServerOrigin ( ) ) . get ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps/' ) >= 0 ; } ) . reply ( 200 , { } ) ;
var fake2 = nock ( settings . apiServerOrigin ( ) ) . delete ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps/' ) >= 0 ; } ) . reply ( 204 , { } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/uninstall' )
. query ( { access _token : token } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 202 ) ;
expect ( fake1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( fake2 . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'app install succeeds again' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake1 = nock ( settings . apiServerOrigin ( ) ) . get ( '/api/v1/apps/' + APP _STORE _ID ) . reply ( 200 , { manifest : APP _MANIFEST } ) ;
var fake2 = nock ( settings . apiServerOrigin ( ) ) . post ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps' ) >= 0 ; } , ( body ) => body . appstoreId === APP _STORE _ID && body . manifestId === APP _MANIFEST . id && body . appId ) . reply ( 201 , { } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { appStoreId : APP _STORE _ID , location : APP _LOCATION _2 , domain : DOMAIN _0 . domain , portBindings : null , accessRestriction : null } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 202 ) ;
expect ( res . body . id ) . to . be . a ( 'string' ) ;
APP _ID = res . body . id ;
expect ( fake1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( fake2 . isDone ( ) ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2018-10-29 11:49:37 -07:00
it ( 'app install fails with developer token' , function ( done ) {
2017-11-23 23:41:01 +01:00
superagent . post ( SERVER _URL + '/api/v1/developer/login' )
2018-04-30 21:41:09 -07:00
. send ( { username : USERNAME , password : PASSWORD } )
. end ( function ( error , result ) {
expect ( error ) . to . not . be . ok ( ) ;
expect ( result . statusCode ) . to . equal ( 200 ) ;
2018-08-30 00:32:38 +02:00
expect ( new Date ( result . body . expires ) . toString ( ) ) . to . not . be ( 'Invalid Date' ) ;
expect ( result . body . accessToken ) . to . be . a ( 'string' ) ;
2017-11-23 23:41:01 +01:00
2018-04-30 21:41:09 -07:00
// overwrite non dev token
2018-08-30 00:32:38 +02:00
token = result . body . accessToken ;
2017-11-23 23:41:01 +01:00
2018-04-30 21:41:09 -07:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2017-11-23 23:41:01 +01:00
. query ( { access _token : token } )
2018-02-02 14:06:01 +01:00
. send ( { manifest : APP _MANIFEST , location : APP _LOCATION + APP _LOCATION , domain : DOMAIN _0 . domain , portBindings : null , accessRestriction : null } )
2017-11-23 23:41:01 +01:00
. end ( function ( err , res ) {
2018-10-29 11:49:37 -07:00
expect ( res . statusCode ) . to . equal ( 424 ) ; // appstore purchase external error
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2016-01-29 16:27:35 +01:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2018-02-05 17:28:30 +01:00
describe ( 'App installation' , function ( ) {
2018-04-30 21:44:24 -07:00
var apiHockInstance = hock . createHock ( { throwOnUnmatched : false } ) ;
2017-02-06 21:53:29 -08:00
var validCert1 , validKey1 ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
before ( function ( done ) {
2018-02-05 22:17:16 +01:00
child _process . execSync ( 'openssl req -subj "/CN=*.' + DOMAIN _0 . domain + '/O=My Company Name LTD./C=US" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /tmp/server.key -out /tmp/server.crt' ) ;
2017-02-06 21:53:29 -08:00
validKey1 = fs . readFileSync ( '/tmp/server.key' , 'utf8' ) ;
validCert1 = fs . readFileSync ( '/tmp/server.crt' , 'utf8' ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
APP _ID = uuid . v4 ( ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
async . series ( [
startBox ,
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
function ( callback ) {
apiHockInstance
. get ( '/api/v1/apps/' + APP _STORE _ID + '/versions/' + APP _MANIFEST . version + '/icon' )
2018-02-05 17:28:30 +01:00
. replyWithFile ( 200 , path . resolve ( _ _dirname , '../../../assets/avatar.png' ) ) ;
2016-01-29 17:24:18 +01:00
2019-07-26 10:49:29 -07:00
var port = parseInt ( url . parse ( settings . apiServerOrigin ( ) ) . port , 10 ) ;
2019-04-18 13:11:56 +02:00
http . createServer ( apiHockInstance . handler ) . listen ( port , callback ) ;
2017-02-06 21:53:29 -08:00
} ,
2015-07-20 00:09:47 -07:00
2018-02-05 17:28:30 +01:00
function ( callback ) {
2019-05-03 16:27:47 -07:00
settingsdb . set ( settings . CLOUDRON _TOKEN _KEY , USER _1 _APPSTORE _TOKEN , function ( error ) {
2018-02-05 17:28:30 +01:00
if ( error ) return callback ( error ) ;
2015-07-20 00:09:47 -07:00
2019-05-03 16:27:47 -07:00
callback ( ) ;
2018-02-05 17:28:30 +01:00
} ) ;
2017-02-06 21:53:29 -08:00
}
] , done ) ;
} ) ;
2015-10-20 11:33:19 -07:00
2017-02-06 21:53:29 -08:00
var appResult = null , appEntry = null ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can install test app' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake1 = nock ( settings . apiServerOrigin ( ) ) . get ( '/api/v1/apps/' + APP _STORE _ID ) . reply ( 200 , { manifest : APP _MANIFEST } ) ;
var fake2 = nock ( settings . apiServerOrigin ( ) ) . post ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps' ) >= 0 ; } , ( body ) => body . appstoreId === APP _STORE _ID && body . manifestId === APP _MANIFEST . id && body . appId ) . reply ( 201 , { } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
var count = 0 ;
function checkInstallStatus ( ) {
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 200 ) ;
2019-04-18 13:11:56 +02:00
2018-04-30 21:41:09 -07:00
if ( res . body . installationState === appdb . ISTATE _INSTALLED ) { appResult = res . body ; return done ( null ) ; }
if ( res . body . installationState === appdb . ISTATE _ERROR ) return done ( new Error ( 'Install error' ) ) ;
2019-04-18 13:11:56 +02:00
if ( ++ count > 500 ) return done ( new Error ( 'Timedout' ) ) ;
2018-04-30 21:41:09 -07:00
setTimeout ( checkInstallStatus , 1000 ) ;
} ) ;
2017-02-06 21:53:29 -08:00
}
2016-01-29 16:27:35 +01:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/install' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. send ( { appStoreId : APP _STORE _ID , location : APP _LOCATION , domain : DOMAIN _0 . domain , portBindings : { ECHO _SERVER _PORT : 7171 } , accessRestriction : null } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 202 ) ;
expect ( fake1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( fake2 . isDone ( ) ) . to . be . ok ( ) ;
APP _ID = res . body . id ;
2019-08-05 07:01:12 -07:00
2018-04-30 21:41:09 -07:00
checkInstallStatus ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2018-08-30 00:32:38 +02:00
xit ( 'installation - image created' , function ( done ) {
2017-02-06 21:53:29 -08:00
expect ( imageCreated ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - can get app' , function ( done ) {
apps . get ( appResult . id , function ( error , app ) {
expect ( ! error ) . to . be . ok ( ) ;
expect ( app ) . to . be . an ( 'object' ) ;
appEntry = app ;
done ( ) ;
2015-07-20 00:09:47 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - container created' , function ( done ) {
expect ( appResult . containerId ) . to . be ( undefined ) ;
expect ( appEntry . containerId ) . to . be . ok ( ) ;
docker . getContainer ( appEntry . containerId ) . inspect ( function ( error , data ) {
expect ( error ) . to . not . be . ok ( ) ;
expect ( data . Config . ExposedPorts [ '7777/tcp' ] ) . to . eql ( { } ) ;
2019-08-05 07:01:12 -07:00
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_WEBADMIN_ORIGIN=' + settings . adminOrigin ( ) ) ;
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_API_ORIGIN=' + settings . adminOrigin ( ) ) ;
2017-02-06 21:53:29 -08:00
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON=1' ) ;
2019-08-05 07:01:12 -07:00
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_APP_ORIGIN=https://' + APP _LOCATION + '.' + DOMAIN _0 . domain ) ;
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_APP_DOMAIN=' + APP _LOCATION + '.' + DOMAIN _0 . domain ) ;
2017-02-06 21:53:29 -08:00
// Hostname must not be set of app fqdn or app location!
expect ( data . Config . Hostname ) . to . not . contain ( APP _LOCATION ) ;
expect ( data . Config . Env ) . to . contain ( 'ECHO_SERVER_PORT=7171' ) ;
expect ( data . HostConfig . PortBindings [ '7778/tcp' ] [ 0 ] . HostPort ) . to . eql ( '7171' ) ;
2015-07-20 00:09:47 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - nginx config' , function ( done ) {
expect ( fs . existsSync ( paths . NGINX _APPCONFIG _DIR + '/' + APP _LOCATION + '.conf' ) ) ;
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - registered subdomain' , function ( done ) {
// this is checked in unregister subdomain testcase
done ( ) ;
} ) ;
it ( 'installation - volume created' , function ( done ) {
2017-03-29 15:51:53 +02:00
expect ( fs . existsSync ( paths . APPS _DATA _DIR + '/' + APP _ID ) ) ;
2018-09-14 10:18:43 -07:00
let volume = docker . getVolume ( APP _ID + '-localstorage' ) ;
volume . inspect ( function ( error , volume ) {
expect ( error ) . to . be ( null ) ;
expect ( volume . Labels . appId ) . to . eql ( APP _ID ) ;
expect ( volume . Options . device ) . to . eql ( paths . APPS _DATA _DIR + '/' + APP _ID + '/data' ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
it ( 'installation - http is up and running' , function ( done ) {
var tryCount = 20 ;
2019-04-18 13:11:56 +02:00
// TODO what does that check for?
2017-02-06 21:53:29 -08:00
expect ( appResult . httpPort ) . to . be ( undefined ) ;
2019-04-18 13:11:56 +02:00
2017-02-06 21:53:29 -08:00
( function healthCheck ( ) {
superagent . get ( 'http://localhost:' + appEntry . httpPort + appResult . manifest . healthCheckPath )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
if ( err || res . statusCode !== 200 ) {
if ( -- tryCount === 0 ) {
console . log ( 'Unable to curl http://localhost:' + appEntry . httpPort + appResult . manifest . healthCheckPath ) ;
return done ( new Error ( 'Timedout' ) ) ;
}
return setTimeout ( healthCheck , 2000 ) ;
2017-04-04 14:47:54 -07:00
}
2017-02-06 21:53:29 -08:00
2018-04-30 21:41:09 -07:00
expect ( ! err ) . to . be . ok ( ) ;
expect ( res . statusCode ) . to . equal ( 200 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - tcp port mapping works' , function ( done ) {
var client = net . connect ( 7171 ) ;
client . on ( 'data' , function ( data ) {
expect ( data . toString ( ) ) . to . eql ( 'ECHO_SERVER_PORT=7171' ) ;
2015-07-20 00:09:47 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
client . on ( 'error' , done ) ;
} ) ;
it ( 'installation - running container has volume mounted' , function ( done ) {
docker . getContainer ( appEntry . containerId ) . inspect ( function ( error , data ) {
expect ( error ) . to . not . be . ok ( ) ;
2018-09-14 10:18:43 -07:00
expect ( data . Mounts . filter ( function ( mount ) { return mount . Destination === '/app/data' ; } ) [ 0 ] . Type ) . to . eql ( 'volume' ) ;
2015-07-20 00:09:47 -07:00
2016-01-29 16:27:35 +01:00
done ( ) ;
2015-07-20 00:09:47 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2019-04-18 13:11:56 +02:00
it ( 'installation - app responds to http request' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . get ( 'http://localhost:' + appEntry . httpPort ) . end ( function ( err , res ) {
expect ( ! err ) . to . be . ok ( ) ;
expect ( res . statusCode ) . to . equal ( 200 ) ;
2015-07-20 00:09:47 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'installation - oauth addon config' , function ( done ) {
var appContainer = docker . getContainer ( appEntry . containerId ) ;
appContainer . inspect ( function ( error , data ) {
expect ( error ) . to . not . be . ok ( ) ;
2015-09-09 15:48:35 -07:00
2017-02-06 21:53:29 -08:00
clients . getByAppIdAndType ( APP _ID , clients . TYPE _OAUTH , function ( error , client ) {
expect ( error ) . to . not . be . ok ( ) ;
expect ( client . id . length ) . to . be ( 40 ) ; // cid- + 32 hex chars (128 bits) + 4 hyphens
expect ( client . clientSecret . length ) . to . be ( 256 ) ; // 32 hex chars (8 * 256 bits)
2019-08-05 07:01:12 -07:00
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_OAUTH_CLIENT_ID=' + client . id ) ;
expect ( data . Config . Env ) . to . contain ( 'CLOUDRON_OAUTH_CLIENT_SECRET=' + client . clientSecret ) ;
2015-09-09 15:48:35 -07:00
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2019-08-05 07:01:12 -07:00
xit ( 'installation - app can populate addons' , function ( done ) {
superagent . get ( ` http://localhost:' ${ appEntry . httpPort } /populate_addons ` ) . end ( function ( err , res ) {
2017-02-06 21:53:29 -08:00
expect ( ! err ) . to . be . ok ( ) ;
expect ( res . statusCode ) . to . equal ( 200 ) ;
for ( var key in res . body ) {
expect ( res . body [ key ] ) . to . be ( 'OK' ) ;
}
done ( ) ;
} ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2019-08-05 07:01:12 -07:00
xit ( 'installation - app can check addons' , function ( done ) {
2017-02-06 21:53:29 -08:00
console . log ( 'This test can take a while as it waits for scheduler addon to tick 3' ) ;
checkAddons ( appEntry , done ) ;
} ) ;
it ( 'installation - redis addon created' , function ( done ) {
checkRedis ( 'redis-' + APP _ID , done ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2019-04-18 13:11:56 +02:00
it ( 'logs - stdout and stderr' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/logs' )
. query ( { access _token : token } )
2019-04-24 14:23:19 -07:00
. buffer ( false )
2017-02-06 21:53:29 -08:00
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
var data = '' ;
res . on ( 'data' , function ( d ) { data += d . toString ( 'utf8' ) ; } ) ;
res . on ( 'end' , function ( ) {
expect ( data . length ) . to . not . be ( 0 ) ;
done ( ) ;
} ) ;
res . on ( 'error' , done ) ;
2016-01-29 16:27:35 +01:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-28 16:33:45 +01:00
2019-04-18 13:11:56 +02:00
it ( 'logStream - requires event-stream accept header' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/logstream' )
. query ( { access _token : token , fromLine : 0 } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . be ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-05-23 20:17:11 -07:00
2019-04-24 16:08:30 -07:00
it ( 'logStream - stream logs' , function ( done ) {
2017-02-06 21:53:29 -08:00
var options = {
2019-07-25 15:43:51 -07:00
port : constants . PORT , host : 'localhost' , path : '/api/v1/apps/' + APP _ID + '/logstream?access_token=' + token ,
2017-02-06 21:53:29 -08:00
headers : { 'Accept' : 'text/event-stream' , 'Connection' : 'keep-alive' }
} ;
// superagent doesn't work. maybe https://github.com/visionmedia/superagent/issues/420
var req = http . get ( options , function ( res ) {
var data = '' ;
2019-04-24 16:08:30 -07:00
res . on ( 'data' , function ( d ) { data += d . toString ( 'utf8' ) ; } ) ;
2017-02-06 21:53:29 -08:00
setTimeout ( function checkData ( ) {
expect ( data . length ) . to . not . be ( 0 ) ;
data . split ( '\n' ) . forEach ( function ( line ) {
if ( line . indexOf ( 'id: ' ) !== 0 ) return ;
2019-04-24 16:08:30 -07:00
expect ( parseInt ( line . substr ( 4 ) , 10 ) ) . to . be . a ( 'number' ) ; // timestamp
2017-02-06 21:53:29 -08:00
} ) ;
req . abort ( ) ;
2016-05-23 20:17:11 -07:00
done ( ) ;
2017-02-06 21:53:29 -08:00
} , 1000 ) ;
res . on ( 'error' , done ) ;
2016-05-23 20:17:11 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
req . on ( 'error' , done ) ;
} ) ;
2019-04-18 13:11:56 +02:00
it ( 'non admin cannot stop app' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/stop' )
. query ( { access _token : token _1 } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 403 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2016-05-23 20:17:11 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can stop app' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/stop' )
. query ( { access _token : token } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 202 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'did stop the app' , function ( done ) {
function waitForAppToDie ( ) {
2019-05-03 14:00:21 -07:00
superagent . get ( 'http://localhost:' + appEntry . httpPort + appResult . manifest . healthCheckPath ) . end ( function ( err ) {
2017-02-06 21:53:29 -08:00
if ( ! err || err . code !== 'ECONNREFUSED' ) return setTimeout ( waitForAppToDie , 500 ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
// wait for app status to be updated
2018-08-30 00:32:38 +02:00
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID ) . query ( { access _token : token } ) . end ( function ( error , result ) {
2017-02-06 21:53:29 -08:00
if ( error || result . statusCode !== 200 || result . body . runState !== 'stopped' ) return setTimeout ( waitForAppToDie , 500 ) ;
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
} ) ;
}
2017-02-06 21:53:29 -08:00
waitForAppToDie ( ) ;
} ) ;
2016-06-04 18:07:02 -07:00
2019-04-18 13:11:56 +02:00
it ( 'nonadmin cannot start app' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/start' )
. query ( { access _token : token _1 } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 403 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can start app' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/start' )
. query ( { access _token : token } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 202 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'did start the app' , function ( done ) {
var count = 0 ;
function checkStartState ( ) {
superagent . get ( 'http://localhost:' + appEntry . httpPort + appResult . manifest . healthCheckPath )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
if ( res && res . statusCode === 200 ) return done ( ) ;
if ( ++ count > 50 ) return done ( new Error ( 'Timedout' ) ) ;
setTimeout ( checkStartState , 500 ) ;
} ) ;
2017-02-06 21:53:29 -08:00
}
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
checkStartState ( ) ;
} ) ;
2019-08-05 07:01:12 -07:00
xit ( 'installation - app can check addons' , function ( done ) {
2017-02-06 21:53:29 -08:00
console . log ( 'This test can take a while as it waits for scheduler addon to tick 2' ) ;
checkAddons ( appEntry , done ) ;
} ) ;
function checkConfigureStatus ( count , done ) {
assert . strictEqual ( typeof count , 'number' ) ;
assert . strictEqual ( typeof done , 'function' ) ;
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 200 ) ;
if ( res . body . installationState === appdb . ISTATE _INSTALLED ) { appResult = res . body ; expect ( appResult ) . to . be . ok ( ) ; return done ( null ) ; }
if ( res . body . installationState === appdb . ISTATE _ERROR ) return done ( new Error ( 'Install error' ) ) ;
if ( ++ count > 50 ) return done ( new Error ( 'Timedout' ) ) ;
setTimeout ( checkConfigureStatus . bind ( null , count , done ) , 1000 ) ;
} ) ;
2017-02-06 21:53:29 -08:00
}
2019-04-18 13:11:56 +02:00
it ( 'cannot reconfigure app with missing domain' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
. query ( { access _token : token } )
. send ( { location : 'hellothre' } )
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with bad location' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { location : 1234 , domain : DOMAIN _0 . domain } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with bad accessRestriction' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { accessRestriction : false } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with only the cert, no key' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { cert : validCert1 } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-13 13:44:23 +02:00
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with only the key, no cert' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { key : validKey1 } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-13 13:44:23 +02:00
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with cert not being a string' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { cert : 1234 , key : validKey1 } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'cannot reconfigure app with key not being a string' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { cert : validCert1 , key : 1234 } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2019-04-16 16:36:11 +02:00
it ( 'cannot reconfigure app with invalid tags' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { tags : 'foobar' } )
2019-04-16 16:36:11 +02:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { tags : [ 'hello' , '' , 'there' ] } )
2019-04-16 16:36:11 +02:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { tags : [ 'hello' , 1234 , 'there' ] } )
2019-04-16 16:36:11 +02:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 400 ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
2019-04-18 13:11:56 +02:00
it ( 'non admin cannot reconfigure app' , function ( done ) {
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token _1 } )
2019-04-18 13:11:56 +02:00
. send ( { location : APP _LOCATION _NEW , domain : DOMAIN _0 . domain , portBindings : { ECHO _SERVER _PORT : 7172 } , accessRestriction : null } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
2019-04-24 15:39:47 -07:00
expect ( res . statusCode ) . to . equal ( 403 ) ;
2018-04-30 21:41:09 -07:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can reconfigure app' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { location : APP _LOCATION _NEW , domain : DOMAIN _0 . domain , portBindings : { ECHO _SERVER _PORT : 7172 } } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 202 ) ;
checkConfigureStatus ( 0 , done ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-28 11:50:50 +01:00
2017-02-06 21:53:29 -08:00
it ( 'changed container id after reconfigure' , function ( done ) {
var oldContainerId = appEntry . containerId ;
apps . get ( appResult . id , function ( error , app ) {
expect ( ! error ) . to . be . ok ( ) ;
expect ( app ) . to . be . an ( 'object' ) ;
appEntry = app ;
expect ( appEntry . containerId ) . to . not . be ( oldContainerId ) ;
done ( ) ;
2015-10-28 11:50:50 +01:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-28 11:50:50 +01:00
2017-02-06 21:53:29 -08:00
it ( 'port mapping works after reconfiguration' , function ( done ) {
setTimeout ( function ( ) {
var client = net . connect ( 7172 ) ;
client . on ( 'data' , function ( data ) {
expect ( data . toString ( ) ) . to . eql ( 'ECHO_SERVER_PORT=7172' ) ;
2016-01-29 16:27:35 +01:00
done ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
client . on ( 'error' , done ) ;
} , 2000 ) ;
} ) ;
2016-01-29 17:24:18 +01:00
2017-02-06 21:53:29 -08:00
it ( 'reconfiguration - redis addon recreated' , function ( done ) {
checkRedis ( 'redis-' + APP _ID , done ) ;
} ) ;
2016-01-29 17:24:18 +01:00
2019-08-05 07:01:12 -07:00
xit ( 'installation - app can check addons' , function ( done ) {
2017-02-06 21:53:29 -08:00
console . log ( 'This test can take a while as it waits for scheduler addon to tick 4' ) ;
checkAddons ( appEntry , done ) ;
} ) ;
2016-01-29 17:24:18 +01:00
2017-02-06 21:53:29 -08:00
it ( 'can reconfigure app with custom certificate' , function ( done ) {
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/configure' )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
2019-04-18 13:11:56 +02:00
. send ( { location : APP _LOCATION _NEW , domain : DOMAIN _0 . domain , portBindings : { ECHO _SERVER _PORT : 7172 } , accessRestriction : null , cert : validCert1 , key : validKey1 } )
2018-04-30 21:41:09 -07:00
. end ( function ( err , res ) {
expect ( res . statusCode ) . to . equal ( 202 ) ;
checkConfigureStatus ( 0 , done ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'can uninstall app' , function ( done ) {
2019-07-26 10:49:29 -07:00
var fake1 = nock ( settings . apiServerOrigin ( ) ) . get ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps/' ) >= 0 ; } ) . reply ( 200 , { } ) ;
var fake2 = nock ( settings . apiServerOrigin ( ) ) . delete ( function ( uri ) { return uri . indexOf ( '/api/v1/cloudronapps/' ) >= 0 ; } ) . reply ( 204 , { } ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
var count = 0 ;
function checkUninstallStatus ( ) {
superagent . get ( SERVER _URL + '/api/v1/apps/' + APP _ID )
2018-04-30 21:41:09 -07:00
. query ( { access _token : token } )
. end ( function ( err , res ) {
2019-04-18 13:11:56 +02:00
if ( res ) console . log ( 'Uninstall progress' , res . body . installationState , res . body . installationProgress ) ;
2018-04-30 21:41:09 -07:00
if ( res . statusCode === 404 ) return done ( null ) ;
if ( ++ count > 50 ) return done ( new Error ( 'Timedout' ) ) ;
setTimeout ( checkUninstallStatus , 1000 ) ;
} ) ;
2017-02-06 21:53:29 -08:00
}
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
superagent . post ( SERVER _URL + '/api/v1/apps/' + APP _ID + '/uninstall' )
. query ( { access _token : token } )
. end ( function ( err , res ) {
2018-04-30 21:41:09 -07:00
expect ( res . statusCode ) . to . equal ( 202 ) ;
2018-02-05 22:17:16 +01:00
2018-04-30 21:41:09 -07:00
expect ( fake1 . isDone ( ) ) . to . be . ok ( ) ;
expect ( fake2 . isDone ( ) ) . to . be . ok ( ) ;
2018-02-05 22:17:16 +01:00
2018-04-30 21:41:09 -07:00
checkUninstallStatus ( ) ;
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-20 11:33:19 -07:00
2017-02-06 21:53:29 -08:00
it ( 'uninstalled - container destroyed' , function ( done ) {
docker . getContainer ( appEntry . containerId ) . inspect ( function ( error , data ) {
expect ( error ) . to . be . ok ( ) ;
expect ( data ) . to . not . be . ok ( ) ;
2016-01-29 16:27:35 +01:00
done ( ) ;
2015-10-27 15:44:47 +01:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-10-27 15:44:47 +01:00
2019-04-18 13:11:56 +02:00
xit ( 'uninstalled - image destroyed' , function ( done ) {
2017-02-06 21:53:29 -08:00
expect ( imageDeleted ) . to . be . ok ( ) ;
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'uninstalled - volume destroyed' , function ( done ) {
2017-03-29 15:51:53 +02:00
expect ( ! fs . existsSync ( paths . APPS _DATA _DIR + '/' + APP _ID ) ) ;
2017-02-06 21:53:29 -08:00
done ( ) ;
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'uninstalled - unregistered subdomain' , function ( done ) {
apiHockInstance . done ( function ( error ) { // checks if all the apiHockServer APIs were called
expect ( ! error ) . to . be . ok ( ) ;
2018-02-05 22:17:16 +01:00
done ( ) ;
2015-07-20 00:09:47 -07:00
} ) ;
2017-02-06 21:53:29 -08:00
} ) ;
2015-07-20 00:09:47 -07:00
2017-02-06 21:53:29 -08:00
it ( 'uninstalled - removed nginx' , function ( done ) {
expect ( ! fs . existsSync ( paths . NGINX _APPCONFIG _DIR + '/' + APP _LOCATION + '.conf' ) ) ;
done ( ) ;
} ) ;
2015-09-09 15:48:35 -07:00
2017-02-06 21:53:29 -08:00
it ( 'uninstalled - removed redis addon' , function ( done ) {
2019-05-03 14:00:21 -07:00
docker . getContainer ( 'redis-' + APP _ID ) . inspect ( function ( error ) {
2017-02-06 21:53:29 -08:00
expect ( error ) . to . be . ok ( ) ;
done ( ) ;
2015-07-20 00:09:47 -07:00
} ) ;
} ) ;
2019-08-05 07:01:12 -07:00
// this is here so that --bail does not stop the box code
it ( 'stop box' , stopBox ) ;
2015-07-20 00:09:47 -07:00
} ) ;