11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif ((!common.hasCrypto) || (!common.hasIntl)) {
51cb0ef41Sopenharmony_ci  common.skip('ESLint tests require crypto and Intl');
61cb0ef41Sopenharmony_ci}
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cicommon.skipIfEslintMissing();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst RuleTester = require('../../tools/node_modules/eslint').RuleTester;
111cb0ef41Sopenharmony_ciconst rule = require('../../tools/eslint-rules/crypto-check');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst message = 'Please add a hasCrypto check to allow this test to be ' +
141cb0ef41Sopenharmony_ci                'skipped when Node is built "--without-ssl".';
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cinew RuleTester().run('crypto-check', rule, {
171cb0ef41Sopenharmony_ci  valid: [
181cb0ef41Sopenharmony_ci    'foo',
191cb0ef41Sopenharmony_ci    'crypto',
201cb0ef41Sopenharmony_ci    `
211cb0ef41Sopenharmony_ci    if (!common.hasCrypto) {
221cb0ef41Sopenharmony_ci      common.skip("missing crypto");
231cb0ef41Sopenharmony_ci    }
241cb0ef41Sopenharmony_ci    require("crypto");
251cb0ef41Sopenharmony_ci    `,
261cb0ef41Sopenharmony_ci    `
271cb0ef41Sopenharmony_ci    if (!common.hasCrypto) {
281cb0ef41Sopenharmony_ci      common.skip("missing crypto");
291cb0ef41Sopenharmony_ci    }
301cb0ef41Sopenharmony_ci    internalBinding("crypto");
311cb0ef41Sopenharmony_ci    `,
321cb0ef41Sopenharmony_ci  ],
331cb0ef41Sopenharmony_ci  invalid: [
341cb0ef41Sopenharmony_ci    {
351cb0ef41Sopenharmony_ci      code: 'require("common")\n' +
361cb0ef41Sopenharmony_ci            'require("crypto")\n' +
371cb0ef41Sopenharmony_ci            'if (!common.hasCrypto) {\n' +
381cb0ef41Sopenharmony_ci            '  common.skip("missing crypto");\n' +
391cb0ef41Sopenharmony_ci            '}',
401cb0ef41Sopenharmony_ci      errors: [{ message }]
411cb0ef41Sopenharmony_ci    },
421cb0ef41Sopenharmony_ci    {
431cb0ef41Sopenharmony_ci      code: 'require("common")\n' +
441cb0ef41Sopenharmony_ci            'require("crypto")',
451cb0ef41Sopenharmony_ci      errors: [{ message }],
461cb0ef41Sopenharmony_ci      output: 'require("common")\n' +
471cb0ef41Sopenharmony_ci              'if (!common.hasCrypto) {' +
481cb0ef41Sopenharmony_ci              ' common.skip("missing crypto");' +
491cb0ef41Sopenharmony_ci              '}\n' +
501cb0ef41Sopenharmony_ci              'require("crypto")'
511cb0ef41Sopenharmony_ci    },
521cb0ef41Sopenharmony_ci    {
531cb0ef41Sopenharmony_ci      code: 'require("common")\n' +
541cb0ef41Sopenharmony_ci            'if (common.foo) {}\n' +
551cb0ef41Sopenharmony_ci            'require("crypto")',
561cb0ef41Sopenharmony_ci      errors: [{ message }],
571cb0ef41Sopenharmony_ci      output: 'require("common")\n' +
581cb0ef41Sopenharmony_ci              'if (!common.hasCrypto) {' +
591cb0ef41Sopenharmony_ci              ' common.skip("missing crypto");' +
601cb0ef41Sopenharmony_ci              '}\n' +
611cb0ef41Sopenharmony_ci              'if (common.foo) {}\n' +
621cb0ef41Sopenharmony_ci              'require("crypto")'
631cb0ef41Sopenharmony_ci    },
641cb0ef41Sopenharmony_ci    {
651cb0ef41Sopenharmony_ci      code: 'require("common")\n' +
661cb0ef41Sopenharmony_ci            'if (common.foo) {}\n' +
671cb0ef41Sopenharmony_ci            'internalBinding("crypto")',
681cb0ef41Sopenharmony_ci      errors: [{ message }],
691cb0ef41Sopenharmony_ci      output: 'require("common")\n' +
701cb0ef41Sopenharmony_ci              'if (!common.hasCrypto) {' +
711cb0ef41Sopenharmony_ci              ' common.skip("missing crypto");' +
721cb0ef41Sopenharmony_ci              '}\n' +
731cb0ef41Sopenharmony_ci              'if (common.foo) {}\n' +
741cb0ef41Sopenharmony_ci              'internalBinding("crypto")'
751cb0ef41Sopenharmony_ci    },
761cb0ef41Sopenharmony_ci  ]
771cb0ef41Sopenharmony_ci});
78