11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors.
21cb0ef41Sopenharmony_ci//
31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a
41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the
51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including
61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish,
71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit
81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the
91cb0ef41Sopenharmony_ci// following conditions:
101cb0ef41Sopenharmony_ci//
111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included
121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software.
131cb0ef41Sopenharmony_ci//
141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci'use strict';
231cb0ef41Sopenharmony_ciconst common = require('../common');
241cb0ef41Sopenharmony_ciconst assert = require('assert');
251cb0ef41Sopenharmony_ciconst fs = require('fs');
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cifunction check(async, sync) {
281cb0ef41Sopenharmony_ci  const argsSync = Array.prototype.slice.call(arguments, 2);
291cb0ef41Sopenharmony_ci  const argsAsync = argsSync.concat(common.mustNotCall());
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  if (sync) {
321cb0ef41Sopenharmony_ci    assert.throws(
331cb0ef41Sopenharmony_ci      () => {
341cb0ef41Sopenharmony_ci        sync.apply(null, argsSync);
351cb0ef41Sopenharmony_ci      },
361cb0ef41Sopenharmony_ci      {
371cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_VALUE',
381cb0ef41Sopenharmony_ci        name: 'TypeError',
391cb0ef41Sopenharmony_ci      });
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  if (async) {
431cb0ef41Sopenharmony_ci    assert.throws(
441cb0ef41Sopenharmony_ci      () => {
451cb0ef41Sopenharmony_ci        async.apply(null, argsAsync);
461cb0ef41Sopenharmony_ci      },
471cb0ef41Sopenharmony_ci      {
481cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_VALUE',
491cb0ef41Sopenharmony_ci        name: 'TypeError'
501cb0ef41Sopenharmony_ci      });
511cb0ef41Sopenharmony_ci  }
521cb0ef41Sopenharmony_ci}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, 'foo\u0000bar');
551cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
561cb0ef41Sopenharmony_cicheck(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc');
571cb0ef41Sopenharmony_cicheck(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');
581cb0ef41Sopenharmony_cicheck(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);
591cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, 'foo\u0000bar', 'abc');
601cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, 'abc', 'foo\u0000bar');
611cb0ef41Sopenharmony_cicheck(fs.lchown, fs.lchownSync, 'foo\u0000bar', 12, 34);
621cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar');
631cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, 'foobar', 'foo\u0000bar');
641cb0ef41Sopenharmony_cicheck(fs.lstat, fs.lstatSync, 'foo\u0000bar');
651cb0ef41Sopenharmony_cicheck(fs.mkdir, fs.mkdirSync, 'foo\u0000bar', '0755');
661cb0ef41Sopenharmony_cicheck(fs.open, fs.openSync, 'foo\u0000bar', 'r');
671cb0ef41Sopenharmony_cicheck(fs.readFile, fs.readFileSync, 'foo\u0000bar');
681cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, 'foo\u0000bar');
691cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, 'foo\u0000bar', { recursive: true });
701cb0ef41Sopenharmony_cicheck(fs.readlink, fs.readlinkSync, 'foo\u0000bar');
711cb0ef41Sopenharmony_cicheck(fs.realpath, fs.realpathSync, 'foo\u0000bar');
721cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, 'foo\u0000bar', 'foobar');
731cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, 'foobar', 'foo\u0000bar');
741cb0ef41Sopenharmony_cicheck(fs.rmdir, fs.rmdirSync, 'foo\u0000bar');
751cb0ef41Sopenharmony_cicheck(fs.stat, fs.statSync, 'foo\u0000bar');
761cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar');
771cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar');
781cb0ef41Sopenharmony_cicheck(fs.truncate, fs.truncateSync, 'foo\u0000bar');
791cb0ef41Sopenharmony_cicheck(fs.unlink, fs.unlinkSync, 'foo\u0000bar');
801cb0ef41Sopenharmony_cicheck(null, fs.unwatchFile, 'foo\u0000bar', common.mustNotCall());
811cb0ef41Sopenharmony_cicheck(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0);
821cb0ef41Sopenharmony_cicheck(null, fs.watch, 'foo\u0000bar', common.mustNotCall());
831cb0ef41Sopenharmony_cicheck(null, fs.watchFile, 'foo\u0000bar', common.mustNotCall());
841cb0ef41Sopenharmony_cicheck(fs.writeFile, fs.writeFileSync, 'foo\u0000bar', 'abc');
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ciconst fileUrl = new URL('file:///C:/foo\u0000bar');
871cb0ef41Sopenharmony_ciconst fileUrl2 = new URL('file:///C:/foo%00bar');
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, fileUrl);
901cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, fileUrl, fs.F_OK);
911cb0ef41Sopenharmony_cicheck(fs.appendFile, fs.appendFileSync, fileUrl, 'abc');
921cb0ef41Sopenharmony_cicheck(fs.chmod, fs.chmodSync, fileUrl, '0644');
931cb0ef41Sopenharmony_cicheck(fs.chown, fs.chownSync, fileUrl, 12, 34);
941cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, fileUrl, 'abc');
951cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, 'abc', fileUrl);
961cb0ef41Sopenharmony_cicheck(fs.lchown, fs.lchownSync, fileUrl, 12, 34);
971cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, fileUrl, 'foobar');
981cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, 'foobar', fileUrl);
991cb0ef41Sopenharmony_cicheck(fs.lstat, fs.lstatSync, fileUrl);
1001cb0ef41Sopenharmony_cicheck(fs.mkdir, fs.mkdirSync, fileUrl, '0755');
1011cb0ef41Sopenharmony_cicheck(fs.open, fs.openSync, fileUrl, 'r');
1021cb0ef41Sopenharmony_cicheck(fs.readFile, fs.readFileSync, fileUrl);
1031cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, fileUrl);
1041cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, fileUrl, { recursive: true });
1051cb0ef41Sopenharmony_cicheck(fs.readlink, fs.readlinkSync, fileUrl);
1061cb0ef41Sopenharmony_cicheck(fs.realpath, fs.realpathSync, fileUrl);
1071cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, fileUrl, 'foobar');
1081cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, 'foobar', fileUrl);
1091cb0ef41Sopenharmony_cicheck(fs.rmdir, fs.rmdirSync, fileUrl);
1101cb0ef41Sopenharmony_cicheck(fs.stat, fs.statSync, fileUrl);
1111cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, fileUrl, 'foobar');
1121cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, 'foobar', fileUrl);
1131cb0ef41Sopenharmony_cicheck(fs.truncate, fs.truncateSync, fileUrl);
1141cb0ef41Sopenharmony_cicheck(fs.unlink, fs.unlinkSync, fileUrl);
1151cb0ef41Sopenharmony_cicheck(null, fs.unwatchFile, fileUrl, assert.fail);
1161cb0ef41Sopenharmony_cicheck(fs.utimes, fs.utimesSync, fileUrl, 0, 0);
1171cb0ef41Sopenharmony_cicheck(null, fs.watch, fileUrl, assert.fail);
1181cb0ef41Sopenharmony_cicheck(null, fs.watchFile, fileUrl, assert.fail);
1191cb0ef41Sopenharmony_cicheck(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, fileUrl2);
1221cb0ef41Sopenharmony_cicheck(fs.access, fs.accessSync, fileUrl2, fs.F_OK);
1231cb0ef41Sopenharmony_cicheck(fs.appendFile, fs.appendFileSync, fileUrl2, 'abc');
1241cb0ef41Sopenharmony_cicheck(fs.chmod, fs.chmodSync, fileUrl2, '0644');
1251cb0ef41Sopenharmony_cicheck(fs.chown, fs.chownSync, fileUrl2, 12, 34);
1261cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, fileUrl2, 'abc');
1271cb0ef41Sopenharmony_cicheck(fs.copyFile, fs.copyFileSync, 'abc', fileUrl2);
1281cb0ef41Sopenharmony_cicheck(fs.lchown, fs.lchownSync, fileUrl2, 12, 34);
1291cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, fileUrl2, 'foobar');
1301cb0ef41Sopenharmony_cicheck(fs.link, fs.linkSync, 'foobar', fileUrl2);
1311cb0ef41Sopenharmony_cicheck(fs.lstat, fs.lstatSync, fileUrl2);
1321cb0ef41Sopenharmony_cicheck(fs.mkdir, fs.mkdirSync, fileUrl2, '0755');
1331cb0ef41Sopenharmony_cicheck(fs.open, fs.openSync, fileUrl2, 'r');
1341cb0ef41Sopenharmony_cicheck(fs.readFile, fs.readFileSync, fileUrl2);
1351cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, fileUrl2);
1361cb0ef41Sopenharmony_cicheck(fs.readdir, fs.readdirSync, fileUrl2, { recursive: true });
1371cb0ef41Sopenharmony_cicheck(fs.readlink, fs.readlinkSync, fileUrl2);
1381cb0ef41Sopenharmony_cicheck(fs.realpath, fs.realpathSync, fileUrl2);
1391cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, fileUrl2, 'foobar');
1401cb0ef41Sopenharmony_cicheck(fs.rename, fs.renameSync, 'foobar', fileUrl2);
1411cb0ef41Sopenharmony_cicheck(fs.rmdir, fs.rmdirSync, fileUrl2);
1421cb0ef41Sopenharmony_cicheck(fs.stat, fs.statSync, fileUrl2);
1431cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, fileUrl2, 'foobar');
1441cb0ef41Sopenharmony_cicheck(fs.symlink, fs.symlinkSync, 'foobar', fileUrl2);
1451cb0ef41Sopenharmony_cicheck(fs.truncate, fs.truncateSync, fileUrl2);
1461cb0ef41Sopenharmony_cicheck(fs.unlink, fs.unlinkSync, fileUrl2);
1471cb0ef41Sopenharmony_cicheck(null, fs.unwatchFile, fileUrl2, assert.fail);
1481cb0ef41Sopenharmony_cicheck(fs.utimes, fs.utimesSync, fileUrl2, 0, 0);
1491cb0ef41Sopenharmony_cicheck(null, fs.watch, fileUrl2, assert.fail);
1501cb0ef41Sopenharmony_cicheck(null, fs.watchFile, fileUrl2, assert.fail);
1511cb0ef41Sopenharmony_cicheck(fs.writeFile, fs.writeFileSync, fileUrl2, 'abc');
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci// An 'error' for exists means that it doesn't exist.
1541cb0ef41Sopenharmony_ci// One of many reasons why this file is the absolute worst.
1551cb0ef41Sopenharmony_cifs.exists('foo\u0000bar', common.mustCall((exists) => {
1561cb0ef41Sopenharmony_ci  assert(!exists);
1571cb0ef41Sopenharmony_ci}));
1581cb0ef41Sopenharmony_ciassert(!fs.existsSync('foo\u0000bar'));
159