Example #1
0
import * as Koa from 'koa';
import * as KoaRouter from 'koa-trie-router';
import * as config from 'config';
import * as _mount from 'koa-mount';

const APP_CONFIG = config.get('app');

export class BaseHandler {
  protected router: KoaRouter;
  protected app: Koa;
  public mount_path: string;

  constructor(app: Koa, prefix) {
    this.app = app;
    this.mount_path = APP_CONFIG.namespace + prefix;
    this.router = new KoaRouter(this.mount_path);
  }

  protected mount() {
    this.app.use(_mount(this.mount_path, this.router.middleware()));
  }
}
import * as config from 'config'
import { expect } from 'chai'
import { Request } from 'express'

import { JwtExtractor } from 'idam/jwtExtractor'

const sessionCookieName = config.get<string>('session.cookieName')

describe('Extracting JWT', () => {
  it('should return token from cookie', () => {
    const jwtValue = 'a'

    const req = {
      cookies: {
        [sessionCookieName]: jwtValue
      }
    } as Request

    expect(JwtExtractor.extract(req)).to.equal(jwtValue)
  })
})
 .get(Paths.mcolEligibilityPage.uri, (req: express.Request, res: express.Response): void => {
   res.render(Paths.mcolEligibilityPage.associatedView, {
     mcolUrl: config.get<string>('mcol.url')
   })
 })
 .some((featureName) => toBoolean(config.get<boolean>(`featureToggles.${featureName}`)))
Example #5
0
import Utils from './utils'
import Requests from './requests'
import * as config from 'config'

// get token from https://steamcommunity.com/saliengame/gettoken
// can add many user
const userList = config.get('token')

let singleton: boolean = false
if (userList.length === 1) {
    singleton = true
}

function getRandomInt(min: number, max: number): number {
    min = Math.ceil(min)
    max = Math.floor(max)
    return Math.floor(Math.random() * (max - min)) + min
}

async function SteamGame(userToken: string) {
    let loggerName = `Saliens (${userToken})`
    if (singleton) {
        loggerName = `Saliens`
    }

    const logger = new Utils.Logger(Utils.Logger.LEVEL_INFO, loggerName)
    const requests = new Requests.SalienGame(userToken, logger)
    let times = 0

    while (true) {
        const bossPlanet = await requests.getBossPlanet()
Example #6
0
  'activitypub-http-fetcher': 1,
  'video-file': 1,
  'email': 5
}
// 2 days
const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2

// 1 hour
let SCHEDULER_INTERVAL = 60000 * 60

// ---------------------------------------------------------------------------

const CONFIG = {
  CUSTOM_FILE: getLocalConfigFilePath(),
  LISTEN: {
    PORT: config.get<number>('listen.port')
  },
  DATABASE: {
    DBNAME: 'peertube' + config.get<string>('database.suffix'),
    HOSTNAME: config.get<string>('database.hostname'),
    PORT: config.get<number>('database.port'),
    USERNAME: config.get<string>('database.username'),
    PASSWORD: config.get<string>('database.password')
  },
  REDIS: {
    HOSTNAME: config.get<string>('redis.hostname'),
    PORT: config.get<number>('redis.port'),
    AUTH: config.get<string>('redis.auth')
  },
  SMTP: {
    HOSTNAME: config.get<string>('smtp.hostname'),
Example #7
0
import * as Koa from 'koa';
import * as Router from 'koa-trie-router';
import * as bodyparser from 'koa-bodyparser';
import * as config from 'config';
import * as jwt from 'jsonwebtoken';
import * as mount from 'koa-mount';
import * as responseTime from 'koa-response-time';
import { UserService } from './routes/users/user.service';
import { BindRoutes } from './routes';

const APP_CONFIG = config.get('app');
const JWT_CONFIG = config.get('jwt');
const app = new Koa();
const userService = new UserService();

// X-Response-Time
app.use(responseTime());

// Body Parsing
app.use(bodyparser());

// 404 Handler
app.use(async (ctx, next) => {
  await next();
  if (ctx.status === 404) {
    ctx.response.status = 404;
    ctx.response.body = {
      error: true,
      message: 'Entity not found'
    };
  }
Example #8
0
import * as config from 'config'
import * as express from 'express'
import * as _ from 'lodash'

import { Eligibility } from 'eligibility/model/eligibility'

const minuteInMilliseconds = 60 * 1000
const cookieTimeToLiveInMinutes = config.get<number>('eligibility.cookie.timeToLiveInMinutes') * minuteInMilliseconds

export const cookieName = 'eligibility-check'

export class CookieEligibilityStore {
  read (req: express.Request, res: express.Response): Eligibility {
    const cookie: string = req.cookies[cookieName]
    return new Eligibility().deserialize(cookie !== undefined ? cookie : undefined)
  }

  write (eligibility: Eligibility, req: express.Request, res: express.Response): void {
    const excludeDisplayValue = (value: any): any | undefined => {
      const property = 'displayValue'

      if (value && typeof value === 'object' && Object.getOwnPropertyDescriptor(value, property)) {
        return _.omit(value, property)
      }
      return undefined
    }
    res.cookie(cookieName, _.cloneDeepWith(eligibility, excludeDisplayValue), { httpOnly: true, secure: true, maxAge: cookieTimeToLiveInMinutes })
  }

  clear (req: express.Request, res: express.Response): void {
    res.clearCookie(cookieName)
Example #9
0
import * as mock from 'nock'
import * as HttpStatus from 'http-status-codes'
import * as config from 'config'

const baseURL = config.get<string>('pay.url')
const endpointPath = '/card-payments'
const paymentsPath = '/payments'

export const paymentInitiateResponse: object = {
  reference: 'RC-1520-4225-4161-2265',
  date_created: '2018-03-07T11:35:42.095+0000',
  status: 'Initiated',
  _links: {
    next_url: {
      href: 'https://www.payments.service.gov.uk/secure/8b647ade-02cc-4c85-938d-4db560404df8',
      method: 'GET'
    }
  }
}

const paymentRetrieveResponse: object = {
  amount: 60,
  description: 'Money Claim issue fee',
  reference: 'RC-1520-4276-0065-8715',
  currency: 'GBP',
  ccd_case_number: 'UNKNOWN',
  case_reference: 'dfd75bac-6d54-4c7e-98f7-50e047d7c7f5',
  channel: 'online',
  method: 'card',
  external_provider: 'gov pay',
  status: 'Success',
Example #10
0
 authenticate: (socket, data: {username: string, password: string}, callback) => {
     return callback(null, data.password === config.get('webPass'))
 }