11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst fs = require('fs'); 71cb0ef41Sopenharmony_ciconst path = require('path'); 81cb0ef41Sopenharmony_ciconst { promises } = fs; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Validate the path argument. 111cb0ef41Sopenharmony_ci[false, 1, {}, [], null, undefined].forEach((i) => { 121cb0ef41Sopenharmony_ci const err = { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE' }; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci assert.throws(() => fs.lchown(i, 1, 1, common.mustNotCall()), err); 151cb0ef41Sopenharmony_ci assert.throws(() => fs.lchownSync(i, 1, 1), err); 161cb0ef41Sopenharmony_ci promises.lchown(false, 1, 1) 171cb0ef41Sopenharmony_ci .then(common.mustNotCall()) 181cb0ef41Sopenharmony_ci .catch(common.expectsError(err)); 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci// Validate the uid and gid arguments. 221cb0ef41Sopenharmony_ci[false, 'test', {}, [], null, undefined].forEach((i) => { 231cb0ef41Sopenharmony_ci const err = { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE' }; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci assert.throws( 261cb0ef41Sopenharmony_ci () => fs.lchown('not_a_file_that_exists', i, 1, common.mustNotCall()), 271cb0ef41Sopenharmony_ci err 281cb0ef41Sopenharmony_ci ); 291cb0ef41Sopenharmony_ci assert.throws( 301cb0ef41Sopenharmony_ci () => fs.lchown('not_a_file_that_exists', 1, i, common.mustNotCall()), 311cb0ef41Sopenharmony_ci err 321cb0ef41Sopenharmony_ci ); 331cb0ef41Sopenharmony_ci assert.throws(() => fs.lchownSync('not_a_file_that_exists', i, 1), err); 341cb0ef41Sopenharmony_ci assert.throws(() => fs.lchownSync('not_a_file_that_exists', 1, i), err); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci promises.lchown('not_a_file_that_exists', i, 1) 371cb0ef41Sopenharmony_ci .then(common.mustNotCall()) 381cb0ef41Sopenharmony_ci .catch(common.expectsError(err)); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci promises.lchown('not_a_file_that_exists', 1, i) 411cb0ef41Sopenharmony_ci .then(common.mustNotCall()) 421cb0ef41Sopenharmony_ci .catch(common.expectsError(err)); 431cb0ef41Sopenharmony_ci}); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci// Validate the callback argument. 461cb0ef41Sopenharmony_ci[false, 1, 'test', {}, [], null, undefined].forEach((i) => { 471cb0ef41Sopenharmony_ci assert.throws(() => fs.lchown('not_a_file_that_exists', 1, 1, i), { 481cb0ef41Sopenharmony_ci name: 'TypeError', 491cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 501cb0ef41Sopenharmony_ci }); 511cb0ef41Sopenharmony_ci}); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ciif (!common.isWindows) { 541cb0ef41Sopenharmony_ci const testFile = path.join(tmpdir.path, path.basename(__filename)); 551cb0ef41Sopenharmony_ci const uid = process.geteuid(); 561cb0ef41Sopenharmony_ci const gid = process.getegid(); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci tmpdir.refresh(); 591cb0ef41Sopenharmony_ci fs.copyFileSync(__filename, testFile); 601cb0ef41Sopenharmony_ci fs.lchownSync(testFile, uid, gid); 611cb0ef41Sopenharmony_ci fs.lchown(testFile, uid, gid, common.mustSucceed(async (err) => { 621cb0ef41Sopenharmony_ci await promises.lchown(testFile, uid, gid); 631cb0ef41Sopenharmony_ci })); 641cb0ef41Sopenharmony_ci} 65