How to use the @hapi/hoek.merge function in @hapi/hoek

To help you get started, we’ve selected a few @hapi/hoek 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 academia-de-codigo / noire-server / test / modules / authorization / controllers / permission.js View on Github external
it('updates a permission', async flags => {
        // cleanup
        flags.onCleanup = function() {
            updateStub.restore();
        };

        // setup
        const fakePermission = { id: 1, action: 'create', resourceId: 10 };
        const entity = { description: 'potato' };
        const updateStub = Sinon.stub(PermissionService, 'update');
        updateStub.withArgs(fakePermission.id, entity).resolves(Hoek.merge(fakePermission, entity));

        server.route({
            method: 'PUT',
            path: '/permission/{id}',
            handler: PermissionCtrl.update
        });

        // exercise
        const response = await server.inject({
            method: 'PUT',
            url: `/permission/${fakePermission.id}`,
            payload: entity
        });

        // validate
        expect(updateStub.calledOnce).to.be.true();
github hydra-newmedia / hapi-sentry / index.js View on Github external
sentryEvent.level = event.channel;

        // use request credentials for capturing user
        if (opts.trackUser) sentryEvent.user = request.auth && request.auth.credentials;
        if (sentryEvent.user) {
          Object.keys(sentryEvent.user) // hide credentials
            .filter(prop => /^(p(ass)?w(or)?(d|t)?|secret)?$/i.test(prop))
            .forEach(prop => delete sentryEvent.user[prop]);
        }

        // some SDK identificator
        sentryEvent.sdk = { name: 'sentry.javascript.node.hapi', version };
        return sentryEvent;
      });

      Hoek.merge(scope, request.sentryScope);
      Sentry.captureException(event.error);
    });
  });
github hapijs / bell / lib / oauth.js View on Github external
if (protocol !== 'https' &&
            settings.isSecure) {

            return h.unauthenticated(Boom.internal('Invalid setting  - isSecure must be set to false for non-https server'), { credentials });
        }

        // Sign-in Initialization

        if (!request.query.code) {
            credentials.query = request.query;

            const nonce = Cryptiles.randomString(internals.nonceLength);
            const query = internals.resolveProviderParams(request, settings.providerParams);

            if (settings.allowRuntimeProviderParams) {
                Hoek.merge(query, request.query);
            }

            query.client_id = settings.clientId;
            query.response_type = 'code';
            query.redirect_uri = internals.location(request, protocol, settings.location);
            query.state = nonce;

            if (settings.runtimeStateCallback) {
                const runtimeState = settings.runtimeStateCallback(request);
                if (runtimeState) {
                    query.state += runtimeState;
                }
            }

            let scope = settings.scope || settings.provider.scope;
            if (typeof scope === 'function') {
github academia-de-codigo / noire-server / lib / modules / authorization / services / user.js View on Github external
.where('username', entity.username)
                      .orWhere('email', entity.email)
                : Promise.resolve([]);

        const [user, equalUsers] = await Promise.all([getUserByID, getEqualUsers]);

        if (!user) {
            throw NSError.RESOURCE_NOT_FOUND();
        }

        // username or email is already taken, we should not update
        if (equalUsers.length > 0 && equalUsers.some(equalUser => equalUser.id !== user.id)) {
            throw NSError.RESOURCE_DUPLICATE();
        }

        Hoek.merge(user, Hoek.clone(entity, { shallow: Repository.User.model.updateFields }));

        if (entity.password) {
            user.password = await Auth.crypt(entity.password);
        }

        return txUserRepository.update(user);
    });
};
github hapijs / bell / test / providers / bitbucket.js View on Github external
it('authenticates with mock', async (flags) => {

        const mock = await Mock.v2(flags);
        const server = Hapi.server({ host: 'localhost', port: 80 });
        await server.register(Bell);

        const custom = Bell.providers.bitbucket();
        Hoek.merge(custom, mock.provider);

        Mock.override('https://api.bitbucket.org/2.0/user', {
            repositories: [{}],
            uuid: '1E9C5160-E436-11E5-9897-4FCB70D5A8C7',
            username: 'steve',
            display_name: 'steve'
        });

        server.auth.strategy('custom', 'bell', {
            password: 'cookie_encryption_password_secure',
            isSecure: false,
            clientId: 'bitbucket',
            clientSecret: 'secret',
            provider: custom
        });
github hapijs / bell / test / providers / linkedin.js View on Github external
it('authenticates with mock', async (flags) => {

        const mock = await Mock.v2(flags);
        const server = Hapi.server({ host: 'localhost', port: 80 });
        await server.register(Bell);

        const custom = Bell.providers.linkedin();
        Hoek.merge(custom, mock.provider);

        const profile = {
            id: '1234567890',
            firstName: {
                localized: {
                    en_US: 'steve'
                },
                preferredLocal: {
                    country: 'US',
                    language: 'en'
                }
            },
            lastName: {
                localized: {
                    en_US: 'smith'
                },
github hapijs / bell / test / providers / slack.js View on Github external
it('authenticates with mock (without extended profile)', async (flags) => {

        const mock = await Mock.v2(flags);
        const server = Hapi.server({ host: 'localhost', port: 80 });
        await server.register(Bell);

        const custom = Bell.providers.slack({ extendedProfile: false });
        Hoek.merge(custom, mock.provider);

        server.auth.strategy('custom', 'bell', {
            password: 'cookie_encryption_password_secure',
            isSecure: false,
            clientId: 'slack',
            clientSecret: 'secret',
            provider: custom
        });

        server.route({
            method: '*',
            path: '/login',
            config: {
                auth: 'custom',
                handler: function (request, h) {
github hapijs / bell / test / oauth.js View on Github external
it('errors on failed token request', async (flags) => {

            const mock = await Mock.v2(flags);
            const server = Hapi.server({ host: 'localhost', port: 8080 });
            await server.register(Bell);

            const custom = Bell.providers.facebook();
            Hoek.merge(custom, mock.provider);

            Mock.override(mock.provider.token, null);

            server.auth.strategy('custom', 'bell', {
                password: 'cookie_encryption_password_secure',
                isSecure: false,
                clientId: 'facebook',
                clientSecret: 'secret',
                provider: custom
            });

            server.route({
                method: '*',
                path: '/login',
                options: {
                    auth: 'custom',
github ExpediaGroup / service-client / lib / hooks.js View on Github external
results.forEach((result) => {
          Hoek.merge(finalData, result)
        })
github academia-de-codigo / noire-server / lib / plugins / logger.js View on Github external
const register = async function(server) {
    Hoek.assert(server.settings.app.name);

    const options = Hoek.merge(internals.options, { name: server.settings.app.name });
    await server.register({ plugin: HapiPino, options });

    server.events.on('route', event => {
        server
            .logger()
            .child({ method: event.method, path: event.path })
            .debug('route');
    });

    server
        .logger()
        .child({ plugin: exports.plugin.name })
        .debug('plugin');
};