diff --git a/src/app.ts b/src/Frost.ts similarity index 71% rename from src/app.ts rename to src/Frost.ts index 7519d6028..70386f4b3 100644 --- a/src/app.ts +++ b/src/Frost.ts @@ -2,7 +2,8 @@ import { getVerifiableClaimSigner } from '@po.et/poet-js' import { MongoClient } from 'mongodb' import * as Pino from 'pino' -import { API } from './api/API' +import { RestServer } from './api/RestServer' +import { Router } from './api/Router' import { Configuration } from './configuration' import { AccountController } from './controllers/AccountController' import { ArchiveController } from './controllers/ArchiveController' @@ -15,11 +16,7 @@ import { loggingConfigurationToPinoConfiguration } from './utils/Logging/Logging import { SendEmail } from './utils/SendEmail' import { Vault } from './utils/Vault/Vault' -import './extensions/Error' - -require('dotenv').config({ path: '.env' }) - -export async function app(localVars: any = {}) { +export async function Frost(localVars: any = {}) { const configuration: Configuration = loadConfigurationWithDefaults(localVars) const logger = Pino(loggingConfigurationToPinoConfiguration(configuration)) @@ -41,14 +38,29 @@ export async function app(localVars: any = {}) { logger.error(e, 'Error with Vault') } - const configurationFrostAPI = configurationToFrostAPI(configuration) - const mongoClient = await MongoClient.connect(configuration.mongodbUrl) const dbConnection = await mongoClient.db() const accountCollection = dbConnection.collection('accounts') const accountDao = AccountDao(accountCollection) - const sendEmail = SendEmail(configurationFrostAPI.sendEmail) + const sendEmail = SendEmail({ + nodemailer: { + mandrill: { + apiKey: configuration.transactionalMandrill, + }, + maildev: { + host: configuration.maildevPortTcpAddr, + port: configuration.maildevPortTcpPort, + ignoreTLS: configuration.maildevIgnoreTLS, + }, + sendEmailDisabled: configuration.sendEmailDisabled, + emailTransportMailDev: configuration.emailTransportMailDev, + }, + emailFrom: configuration.emailFrom, + emailReply: configuration.emailReply, + frostChangePassword: configuration.frostChangePassword, + frostVerifiedAccount: configuration.frostVerifiedAccount, + }) const mainnetNode = PoetNode(configuration.poetUrl) const testnetNode = PoetNode(configuration.testPoetUrl) @@ -90,57 +102,48 @@ export async function app(localVars: any = {}) { }, }) - const frostAPI = await API(accountController, archiveController, workController)(configurationFrostAPI).start() + const router = Router({ + configuration: { + passwordComplexity: { + min: configuration.passwordComplexMin, + max: configuration.passwordComplexMax, + lowerCase: configuration.passwordComplexLowerCase, + upperCase: configuration.passwordComplexUpperCase, + numeric: configuration.passwordComplexNumeric, + symbol: configuration.passwordComplexSymbol, + }, + maxApiTokens: configuration.maxApiTokens, + }, + dependencies: { + accountController, + archiveController, + workController, + }, + }) + + const restServer = await RestServer({ + configuration: { + host: configuration.frostHost, + port: configuration.frostPort, + maxApiRequestLimitForm: configuration.maxApiRequestLimitForm, + maxApiRequestLimitJson: configuration.maxApiRequestLimitJson, + loggingConfiguration: { + loggingLevel: configuration.loggingLevel, + loggingPretty: configuration.loggingPretty, + }, + }, + dependencies: { + router, + }, + }) await accountDao.createIndices() return { stop: async () => { - await frostAPI.stop() + await restServer.stop() await mongoClient.close() return true }, } } - -const configurationToFrostAPI = (configuration: Configuration) => ({ - host: configuration.frostHost, - port: configuration.frostPort, - maxApiRequestLimitForm: configuration.maxApiRequestLimitForm, - maxApiRequestLimitJson: configuration.maxApiRequestLimitJson, - passwordComplex: { - min: configuration.passwordComplexMin, - max: configuration.passwordComplexMax, - lowerCase: configuration.passwordComplexLowerCase, - upperCase: configuration.passwordComplexUpperCase, - numeric: configuration.passwordComplexNumeric, - symbol: configuration.passwordComplexSymbol, - }, - sendEmail: { - nodemailer: { - mandrill: { - apiKey: configuration.transactionalMandrill, - }, - maildev: { - host: configuration.maildevPortTcpAddr, - port: configuration.maildevPortTcpPort, - ignoreTLS: configuration.maildevIgnoreTLS, - }, - sendEmailDisabled: configuration.sendEmailDisabled, - emailTransportMailDev: configuration.emailTransportMailDev, - }, - emailFrom: configuration.emailFrom, - emailReply: configuration.emailReply, - frostChangePassword: configuration.frostChangePassword, - frostVerifiedAccount: configuration.frostVerifiedAccount, - }, - poetUrl: configuration.poetUrl, - testPoetUrl: configuration.testPoetUrl, - maxApiTokens: configuration.maxApiTokens, - verifiedAccount: configuration.verifiedAccount, - pwnedCheckerRoot: configuration.pwnedCheckerRoot, - loggingConfiguration: { - loggingLevel: configuration.loggingLevel, - loggingPretty: configuration.loggingPretty, - }, -}) diff --git a/src/api/API.ts b/src/api/API.ts deleted file mode 100644 index abbd78cee..000000000 --- a/src/api/API.ts +++ /dev/null @@ -1,117 +0,0 @@ -import * as Koa from 'koa' -import * as bodyParser from 'koa-bodyparser' -import * as helmet from 'koa-helmet' -import * as cors from 'koa2-cors' -import * as Pino from 'pino' - -import { securityHeaders } from '../securityHeaders' -import { createModuleLogger, LoggingConfiguration } from '../utils/Logging/Logging' -import { SendEmailConfiguration } from '../utils/SendEmail' - -import { AccountController } from '../controllers/AccountController' -import { ArchiveController } from '../controllers/ArchiveController' -import { WorkController } from '../controllers/WorkController' -import { errorHandling } from '../middlewares/errorHandling' -import { logger } from '../middlewares/logger' - -import { PasswordComplexConfiguration } from './PasswordComplexConfiguration' -import { routes } from './routes' - -interface APIConnection { - host: string - port: number -} - -interface APIConfiguration extends APIConnection { - maxApiRequestLimitForm: string - maxApiRequestLimitJson: string - host: string - port: number - passwordComplex: PasswordComplexConfiguration - sendEmail: SendEmailConfiguration - poetUrl: string - testPoetUrl: string - maxApiTokens: number - verifiedAccount: boolean - pwnedCheckerRoot: string - loggingConfiguration: LoggingConfiguration -} - -interface APIMethods { - start(): Promise - stop(): Promise -} - -const init = ( - accountController: AccountController, - archiveController: ArchiveController, - workController: WorkController, -) => ({ - maxApiRequestLimitForm, - maxApiRequestLimitJson, - passwordComplex, - sendEmail, - maxApiTokens, - loggingConfiguration, -}: APIConfiguration) => { - const app = new Koa() - const route = routes(accountController, archiveController, workController)( - passwordComplex, - sendEmail, - maxApiTokens, - ) - - app - .use(errorHandling()) - .use(logger(createModuleLogger(loggingConfiguration))) - .use(helmet(securityHeaders)) - .use( - cors({ - origin: (ctx: any, next: any) => '*', - }), - ) - .use( - bodyParser({ - formLimit: maxApiRequestLimitForm, - jsonLimit: maxApiRequestLimitJson, - }), - ) - .use(route.routes()) - .use(route.allowedMethods()) - - return app -} - -const startAPI = async (app: any, configuration: APIConnection, logger: Pino.Logger) => { - logger.info('Starting API...') - const server = await app.listen(configuration.port, configuration.host) - logger.info('Started API.') - return server -} - -const stopAPI = async (server: any, logger: Pino.Logger) => { - logger.info('Stopping API...') - await server.close() - logger.info('Stopped API.') -} - -export const API = ( - accountController: AccountController, - archiveController: ArchiveController, - workController: WorkController, -) => (configuration: APIConfiguration): APIMethods => { - const { loggingConfiguration } = configuration - const logger = createModuleLogger(loggingConfiguration)(__dirname) - - return { - async start(): Promise { - const app = init(accountController, archiveController, workController)(configuration) - this.server = await startAPI(app, configuration, logger) - return this - }, - async stop(): Promise { - await stopAPI(this.server, logger) - return this - }, - } -} diff --git a/src/api/PasswordComplexConfiguration.ts b/src/api/PasswordComplexityConfiguration.ts similarity index 75% rename from src/api/PasswordComplexConfiguration.ts rename to src/api/PasswordComplexityConfiguration.ts index 765353900..e5a0e0b17 100644 --- a/src/api/PasswordComplexConfiguration.ts +++ b/src/api/PasswordComplexityConfiguration.ts @@ -1,4 +1,4 @@ -export interface PasswordComplexConfiguration { +export interface PasswordComplexityConfiguration { readonly min: number readonly max: number readonly lowerCase: number diff --git a/src/api/RestServer.ts b/src/api/RestServer.ts new file mode 100644 index 000000000..5ab2be082 --- /dev/null +++ b/src/api/RestServer.ts @@ -0,0 +1,92 @@ +import * as Koa from 'koa' +import * as bodyParser from 'koa-bodyparser' +import * as helmet from 'koa-helmet' +import * as KoaRouter from 'koa-router' +import * as cors from 'koa2-cors' + +import { securityHeaders } from '../securityHeaders' +import { createModuleLogger, LoggingConfiguration } from '../utils/Logging/Logging' + +import { errorHandling } from '../middlewares/errorHandling' +import { logger } from '../middlewares/logger' + +interface Configuration { + readonly host: string + readonly port: number + readonly maxApiRequestLimitForm: string + readonly maxApiRequestLimitJson: string + readonly loggingConfiguration: LoggingConfiguration +} + +interface Dependencies { + readonly router: KoaRouter +} + +interface Arguments { + readonly configuration: Configuration + readonly dependencies: Dependencies +} + +interface APIMethods { + readonly stop: () => Promise +} + +export const RestServer = async ({ + configuration: { + port, + host, + maxApiRequestLimitForm, + maxApiRequestLimitJson, + loggingConfiguration, + }, + dependencies: { + router, + }, +}: Arguments): Promise => { + const logger = createModuleLogger(loggingConfiguration)(__dirname) + + const koa = ConfiguredKoa({ + maxApiRequestLimitForm, + maxApiRequestLimitJson, + loggingConfiguration, + }) + + koa + .use(router.routes()) + .use(router.allowedMethods()) + + logger.info('Starting HTTP Server...') + const server = await koa.listen(port, host) + logger.info('Started HTTP Server.') + + const stop = async () => { + logger.info('Stopping HTTP Server...') + await server.close() + logger.info('Stopped HTTP Server.') + } + + return { + stop, + } +} + +const ConfiguredKoa = ({ + maxApiRequestLimitForm, + maxApiRequestLimitJson, + loggingConfiguration, +}: Partial) => + new Koa() + .use(errorHandling()) + .use(logger(createModuleLogger(loggingConfiguration))) + .use(helmet(securityHeaders)) + .use( + cors({ + origin: (ctx: any, next: any) => '*', + }), + ) + .use( + bodyParser({ + formLimit: maxApiRequestLimitForm, + jsonLimit: maxApiRequestLimitJson, + }), + ) diff --git a/src/api/routes.ts b/src/api/Router.ts similarity index 82% rename from src/api/routes.ts rename to src/api/Router.ts index a5070816c..674fd21a1 100644 --- a/src/api/routes.ts +++ b/src/api/Router.ts @@ -10,9 +10,8 @@ import { isLoggedIn } from '../middlewares/isLoggedIn' import { monitor } from '../middlewares/monitor' import { requireEmailVerified } from '../middlewares/requireEmailVerified' import { validate } from '../middlewares/validate' -import { SendEmailConfiguration } from '../utils/SendEmail' -import { PasswordComplexConfiguration } from './PasswordComplexConfiguration' +import { PasswordComplexityConfiguration } from './PasswordComplexityConfiguration' import { Path } from './Path' import { CreateAccount, CreateAccountSchema } from './accounts/CreateAccount' @@ -42,15 +41,33 @@ import { GetWorks } from './works/GetWorks' import { PostArchive } from './archives/PostArchive' -export const routes = ( - accountController: AccountController, - archiveController: ArchiveController, - workController: WorkController, -) => ( - passwordComplexConfiguration: PasswordComplexConfiguration, - sendEmailConfiguration: SendEmailConfiguration, - maxApiTokens: number, -) => { +interface Configuration { + readonly passwordComplexity: PasswordComplexityConfiguration, + readonly maxApiTokens: number, +} + +interface Dependencies { + readonly accountController: AccountController, + readonly archiveController: ArchiveController, + readonly workController: WorkController, +} + +interface Arguments { + readonly configuration: Configuration + readonly dependencies: Dependencies +} + +export const Router = ({ + configuration: { + passwordComplexity, + maxApiTokens, + }, + dependencies: { + accountController, + archiveController, + workController, + }, +}: Arguments) => { const router = new KoaRouter() const authentication = Authentication(accountController) const authorization = Authorization() @@ -62,10 +79,6 @@ export const routes = ( return next() }) - router.use([Path.PASSWORD_CHANGE, Path.PASSWORD_CHANGE_TOKEN, Path.PASSWORD_RESET]) - router.use([Path.ACCOUNTS]) - router.use([Path.LOGIN]) - router.use( [ Path.ACCOUNTS_VERIFY_TOKEN, @@ -88,9 +101,11 @@ export const routes = ( const secureKeys = ['password', 'token', 'tokenId'] router.use(monitor(secureKeys)) + router.get(Path.HEALTH, GetHealth()) + router.post( Path.ACCOUNTS, - validate({ body: CreateAccountSchema(passwordComplexConfiguration) }), + validate({ body: CreateAccountSchema(passwordComplexity) }), CreateAccount(accountController), ) router.get( @@ -112,6 +127,11 @@ export const routes = ( validate(PatchAccountSchema), PatchAccount(accountController), ) + router.post( + Path.LOGIN, + validate({ body: LoginSchema }), + Login(accountController), + ) router.post( Path.ACCOUNTS_ID_POE_CHALLENGE, authentication, @@ -125,15 +145,14 @@ export const routes = ( validate({ body: ForgotPasswordSchema }), ForgotPassword(accountController), ) - router.post(Path.LOGIN, validate({ body: LoginSchema }), Login(accountController)) router.post( Path.PASSWORD_CHANGE, - validate({ body: PasswordChangeSchema(passwordComplexConfiguration) }), + validate({ body: PasswordChangeSchema(passwordComplexity) }), PasswordChange(accountController), ) router.post( Path.PASSWORD_CHANGE_TOKEN, - validate({ body: PasswordChangeTokenSchema(passwordComplexConfiguration) }), + validate({ body: PasswordChangeTokenSchema(passwordComplexity) }), PasswordChangeToken(accountController), ) router.post(Path.ACCOUNTS_VERIFY, VerifyAccount(accountController)) @@ -141,7 +160,6 @@ export const routes = ( router.post(Path.TOKENS, CreateToken(maxApiTokens, accountController)) router.get(Path.TOKENS, GetToken(accountController)) - router.get(Path.HEALTH, GetHealth()) router.del(Path.TOKENS_TOKENID, validate({ params: RemoveTokenSchema }), RemoveToken(accountController)) router.post( diff --git a/src/api/accounts/CreateAccount.ts b/src/api/accounts/CreateAccount.ts index 84897e662..d3e665094 100644 --- a/src/api/accounts/CreateAccount.ts +++ b/src/api/accounts/CreateAccount.ts @@ -1,11 +1,11 @@ import * as Joi from 'joi' -import { PasswordComplexConfiguration } from '../../api/PasswordComplexConfiguration' import { AccountController } from '../../controllers/AccountController' import { validatePassword } from '../../helpers/validatePassword' +import { PasswordComplexityConfiguration } from '../PasswordComplexityConfiguration' export const CreateAccountSchema = ( - passwordComplex: PasswordComplexConfiguration, + passwordComplex: PasswordComplexityConfiguration, ) => ({ password }: { password: string }) => ({ email: Joi.string() .email() diff --git a/src/api/accounts/PasswordChange.ts b/src/api/accounts/PasswordChange.ts index 3b1f20e61..3391e9fe8 100644 --- a/src/api/accounts/PasswordChange.ts +++ b/src/api/accounts/PasswordChange.ts @@ -2,10 +2,10 @@ import * as Joi from 'joi' import { AccountController } from '../../controllers/AccountController' import { validatePassword } from '../../helpers/validatePassword' -import { PasswordComplexConfiguration } from '../PasswordComplexConfiguration' +import { PasswordComplexityConfiguration } from '../PasswordComplexityConfiguration' export const PasswordChangeSchema = ( - passwordComplex: PasswordComplexConfiguration, + passwordComplex: PasswordComplexityConfiguration, ) => ({ password }: { password: string }) => ({ password: validatePassword(password, passwordComplex), oldPassword: Joi.string(), diff --git a/src/api/accounts/PasswordChangeToken.ts b/src/api/accounts/PasswordChangeToken.ts index a98c89bd2..1629c28c8 100644 --- a/src/api/accounts/PasswordChangeToken.ts +++ b/src/api/accounts/PasswordChangeToken.ts @@ -1,9 +1,9 @@ import { AccountController } from '../../controllers/AccountController' import { validatePassword } from '../../helpers/validatePassword' -import { PasswordComplexConfiguration } from '../PasswordComplexConfiguration' +import { PasswordComplexityConfiguration } from '../PasswordComplexityConfiguration' export const PasswordChangeTokenSchema = ( - passwordComplex: PasswordComplexConfiguration, + passwordComplex: PasswordComplexityConfiguration, ) => ({ password }: { password: string }) => ({ password: validatePassword(password, passwordComplex), }) diff --git a/src/helpers/validatePassword.ts b/src/helpers/validatePassword.ts index eb1be0c02..9390619e9 100644 --- a/src/helpers/validatePassword.ts +++ b/src/helpers/validatePassword.ts @@ -1,17 +1,18 @@ import * as Joi from 'joi' const PasswordComplexity = require('joi-password-complexity') -import { PasswordComplexConfiguration } from '../api/PasswordComplexConfiguration' +import { PasswordComplexityConfiguration } from '../api/PasswordComplexityConfiguration' -export const validatePassword = (password: string, passwordComplexity: PasswordComplexConfiguration) => +export const validatePassword = (password: string, passwordComplexity: PasswordComplexityConfiguration) => Joi.validate(password, new PasswordComplexity(passwordComplexity), (err: Joi.Err, value: string) => { if (err) throw getTextErrorPassword(passwordComplexity) return value }) -const getTextErrorPassword = (options: PasswordComplexConfiguration) => `Password requirements: ${mapOptions(options)}.` +const getTextErrorPassword = (options: PasswordComplexityConfiguration) => + `Password requirements: ${mapOptions(options)}.` -const mapOptions = (options: PasswordComplexConfiguration) => Object +const mapOptions = (options: PasswordComplexityConfiguration) => Object .entries(options) .map(([key, value]) => `${key}: ${value}`) .join(', ') diff --git a/src/index.ts b/src/index.ts index adba8ee02..c30f5f90f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,12 @@ #!/usr/bin/env node /* tslint:disable:no-console */ -import { app } from './app' +import { Frost } from './Frost' -app() +import './extensions/Error' + +require('dotenv').config({ path: '.env' }) + +Frost() .then(server => process.on('SIGINT', () => server.stop())) .catch(console.error) diff --git a/src/middlewares/authorization.ts b/src/middlewares/authorization.ts index 67d0ec68c..f6ecdaf1b 100644 --- a/src/middlewares/authorization.ts +++ b/src/middlewares/authorization.ts @@ -1,8 +1,4 @@ export const Authorization = () => async (ctx: any, next: any) => { - // TODO: add configuration to ctx in app.ts so middlewares have access. - // This is needed until we can figure out how to restart vault between - // individual tests. - // Currently a hack used to prevent errors in integration tests. if (process.env.SKIP_VAULT === 'true') return (ctx.status = 404) const { user } = ctx.state diff --git a/tests/helpers/utils.ts b/tests/helpers/utils.ts index 11236c301..76531f6de 100644 --- a/tests/helpers/utils.ts +++ b/tests/helpers/utils.ts @@ -1,7 +1,7 @@ /* tslint:disable:no-relative-imports */ import { promisify } from 'util' -import { app } from '../../src/app' +import { Frost } from '../../src/Frost' import { dbHelper } from './database' export const FROST_HOST = 'localhost' @@ -41,7 +41,7 @@ export const setUpServerAndDb = async ({ blockchainSettings?: any, }) => { const db = await createDatabase(PREFIX) - const server = await app({ + const server = await Frost({ BITCOIN_URL: process.env.BITCOIN_URL || 'bitcoind-1', API_PORT: NODE_PORT, MONGODB_DATABASE: db.settings.tempDbName, diff --git a/tests/integration/app.test.ts b/tests/integration/app.test.ts index 2433517c2..4c461f31a 100644 --- a/tests/integration/app.test.ts +++ b/tests/integration/app.test.ts @@ -6,13 +6,13 @@ import { describe } from 'riteway' -import { app } from '../../src/app' +import { Frost } from '../../src/Frost' import { delay, runtimeId, createDatabase } from '../helpers/utils' describe('gracefully stopping the application', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT: '30080', FROST_HOST: 'localhost', FROST_URL: 'http://localhost:30080', @@ -28,7 +28,7 @@ describe('gracefully stopping the application', async assert => { const actual = await server.stop() assert({ - given: 'a running app', + given: 'a running Frost', should: `exit when stop() is called`, actual, expected: true, diff --git a/tests/integration/cors.test.ts b/tests/integration/cors.test.ts index 7f3b006ee..4efb9c59b 100644 --- a/tests/integration/cors.test.ts +++ b/tests/integration/cors.test.ts @@ -2,14 +2,14 @@ import fetch from 'node-fetch' import { describe } from 'riteway' +import { Frost } from '../../src/Frost' import { Path } from '../../src/api/Path' -import { app } from '../../src/app' import { getHeader, delay, runtimeId, createDatabase } from '../helpers/utils' describe('CORS header exists when calling every known route', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT: '30080', FROST_HOST: 'localhost', FROST_URL: 'http://localhost:30080', diff --git a/tests/integration/create-account.test.ts b/tests/integration/create-account.test.ts index 3d5bab160..3af1f728d 100644 --- a/tests/integration/create-account.test.ts +++ b/tests/integration/create-account.test.ts @@ -1,8 +1,8 @@ import fetch from 'node-fetch' import { describe } from 'riteway' +import { Frost } from '../../src/Frost' import { Path } from '../../src/api/Path' -import { app } from '../../src/app' import { testUserEmail, testUserPassword, @@ -23,7 +23,7 @@ const createUserOptions = { describe('Requesting create of an already existing account', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, MONGODB_DATABASE: db.settings.tempDbName, @@ -58,7 +58,7 @@ describe('Requesting create of an already existing account', async assert => { describe('Successfully create a user account', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, MONGODB_DATABASE: db.settings.tempDbName, diff --git a/tests/integration/health.test.ts b/tests/integration/health.test.ts index 3ac0ed5dd..746fe2ea0 100644 --- a/tests/integration/health.test.ts +++ b/tests/integration/health.test.ts @@ -2,8 +2,8 @@ import fetch from 'node-fetch' import { describe } from 'riteway' +import { Frost } from '../../src/Frost' import { Path } from '../../src/api/Path' -import { app } from '../../src/app' import { FROST_HOST, FROST_PORT, FROST_URL, delay, runtimeId, createDatabase } from '../helpers/utils' const options = { @@ -13,7 +13,7 @@ const options = { describe('gracefully stopping the application', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, FROST_URL, diff --git a/tests/integration/index.ts b/tests/integration/index.ts index 77d80abc9..c7a77f62d 100644 --- a/tests/integration/index.ts +++ b/tests/integration/index.ts @@ -1,4 +1,7 @@ /* tslint:disable:no-relative-imports */ + +require('dotenv').config({ path: '.env' }) + import './app.test' import './cors.test' import './create-account.test' diff --git a/tests/integration/login.test.ts b/tests/integration/login.test.ts index 70314360e..efa1bc9a8 100644 --- a/tests/integration/login.test.ts +++ b/tests/integration/login.test.ts @@ -1,8 +1,8 @@ import fetch from 'node-fetch' import { describe } from 'riteway' +import { Frost } from '../../src/Frost' import { Path } from '../../src/api/Path' -import { app } from '../../src/app' import { createUser } from '../helpers/user' import { testUserEmail, @@ -18,7 +18,7 @@ import { describe('Login to an existing account', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, FROST_URL, @@ -102,7 +102,7 @@ describe('Login to an existing account', async assert => { describe('Login to an non-existent account', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, FROST_URL, diff --git a/tests/integration/securityHeaders.test.ts b/tests/integration/securityHeaders.test.ts index d4f97e48c..a2da4e90a 100644 --- a/tests/integration/securityHeaders.test.ts +++ b/tests/integration/securityHeaders.test.ts @@ -1,6 +1,6 @@ import fetch from 'node-fetch' import { describe } from 'riteway' -import { app } from '../../src/app' +import { Frost } from '../../src/Frost' import { delay, runtimeId, createDatabase } from '../helpers/utils' const features = [ @@ -29,7 +29,7 @@ const features = [ describe('Security headers', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT: '30080', FROST_HOST: 'localhost', FROST_URL: 'http://localhost:30080', @@ -44,7 +44,7 @@ describe('Security headers', async assert => { features.forEach(async feature => { assert({ - given: 'a running app', + given: 'a running Frost', should: `Should be ${feature.expected} for the header ${feature.value}`, actual: result.headers.get(feature.value), expected: feature.expected, diff --git a/tests/integration/upload-archive.test.ts b/tests/integration/upload-archive.test.ts index fd72d5154..21d25289f 100644 --- a/tests/integration/upload-archive.test.ts +++ b/tests/integration/upload-archive.test.ts @@ -4,8 +4,8 @@ import { privateToAddress, ecsign, hashPersonalMessage, toRpcSig } from 'ethereu import fetch from 'node-fetch' import { describe } from 'riteway' +import { Frost } from '../../src/Frost' import { Path } from '../../src/api/Path' -import { app } from '../../src/app' import { testUserEmail, testUserPassword, @@ -26,7 +26,7 @@ const createUserOptions = { describe('Try to upload an archive without Proof of POE', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, MONGODB_DATABASE: db.settings.tempDbName, @@ -102,7 +102,7 @@ describe('Try to upload an archive without Proof of POE', async assert => { describe('Try to upload an archive with Proof of POE but without POE balance', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, MONGODB_DATABASE: db.settings.tempDbName, @@ -264,7 +264,7 @@ describe('Try to upload an archive with Proof of POE but without POE balance', a describe('Upload an archive with Proof of POE with enough POE balance', async assert => { const db = await createDatabase(`test-integration-frost-api-poet-${runtimeId()}`) - const server = await app({ + const server = await Frost({ FROST_PORT, FROST_HOST, MONGODB_DATABASE: db.settings.tempDbName,