How to use the @adonisjs/encryption/build/standalone.Encryption function in @adonisjs/encryption

To help you get started, we’ve selected a few @adonisjs/encryption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adonisjs / adonis-framework / test / cors.spec.ts View on Github external
*/

/// 

import test from 'japa'
import supertest from 'supertest'
import { createServer } from 'http'
import { Logger } from '@adonisjs/logger/build/standalone'
import { Profiler } from '@adonisjs/profiler/build/standalone'
import { Encryption } from '@adonisjs/encryption/build/standalone'
import { HttpContext } from '@adonisjs/http-server/build/standalone'

import { Cors } from '../src/Hooks/Cors'
import { specFixtures } from './fixtures/cors'

const encryption = new Encryption('verylongandrandom32characterskey')

test.group('Cors', () => {
  specFixtures.forEach((fixture) => {
    test(fixture.title, async (assert) => {
      const server = createServer(async (req, res) => {
        const cors = new Cors(fixture.configureOptions())
        const logger = new Logger({ name: 'adonis', enabled: false, level: 'trace' })

        fixture.configureRequest(req)
        const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption, req, res)
        await cors.handle(ctx)

        if (!ctx.response.hasLazyBody) {
          ctx.response.send(null)
        }
github adonisjs / adonis-validation-provider / test / request.spec.ts View on Github external
*/

/// 

import test from 'japa'
import { Socket } from 'net'
import { IncomingMessage, ServerResponse } from 'http'
import { Encryption } from '@adonisjs/encryption/build/standalone'
import { RequestConstructorContract } from '@ioc:Adonis/Core/Request'
import { Request as BaseRequest } from '@adonisjs/http-server/build/src/Request'

import extendRequest from '../src/Bindings/Request'
import { Validator } from '../src/Validator'

const Request = BaseRequest as unknown as RequestConstructorContract
const encryption = new Encryption('verylongandrandom32charsecretkey')
const requestConfig = {
  subdomainOffset: 2,
  generateRequestId: false,
  allowMethodSpoofing: false,
  trustProxy: () => true,
}

test.group('Extend Request', () => {
  test('validate data using request', async (assert) => {
    const validator = new Validator({})
    extendRequest(Request, validator.validate, validator.validateAll)

    const req = new IncomingMessage(new Socket())
    const res = new ServerResponse(req)
    const request = new Request(req, res, encryption, requestConfig)
github adonisjs / adonis-framework / test / exception-handler.spec.ts View on Github external
import test from 'japa'
import { Exception } from '@poppinss/utils'
import { FakeLogger } from '@adonisjs/logger/build/standalone'
import { Profiler } from '@adonisjs/profiler/build/standalone'
import { HttpContext } from '@adonisjs/http-server/build/standalone'
import { Encryption } from '@adonisjs/encryption/build/standalone'
import { HttpExceptionHandler } from '../src/HttpExceptionHandler'

const loggerConfig = {
  name: 'adonis-app',
  enabled: true,
  messageKey: 'msg',
  level: 'debug',
}

const encryption = new Encryption('verylongandrandom32characterskey')

test.group('HttpExceptionHandler', () => {
  test('do not report error if error code is in ignore list', (assert) => {
    class AppHandler extends HttpExceptionHandler {
      protected dontReport = ['E_BAD_REQUEST']
    }

    const logger = new FakeLogger(loggerConfig)
    const handler = new AppHandler(logger)

    const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption)
    handler.report(new Exception('bad request', 500, 'E_BAD_REQUEST'), ctx)

    assert.deepEqual(logger.logs, [])
  })

@adonisjs/encryption

Encryption provider for AdonisJs

MIT
Latest version published 7 months ago

Package Health Score

64 / 100
Full package analysis

Popular @adonisjs/encryption functions