CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
test.js148 linesDownload Raw Back to test
1'use strict';2 3var expect = require('expect.js');4var commandExists = require('..');5var commandExistsSync = commandExists.sync;6var resolve = require('path').resolve;7var isUsingWindows = process.platform == 'win32'8 9describe('commandExists', function(){10    describe('async - callback', function() {11        it('it should find a command named ls or xcopy', function(done){12            var commandToUse = 'ls'13            if (isUsingWindows) {14                commandToUse = 'xcopy'15            }16 17            commandExists(commandToUse, function(err, exists) {18                expect(err).to.be(null);19                expect(exists).to.be(true);20                done();21            });22        });23 24        it('it should not find a command named fdsafdsafdsafdsafdsa', function(done){25            commandExists('fdsafdsafdsafdsafdsa', function(err, exists) {26                expect(err).to.be(null);27                expect(exists).to.be(false);28                done();29            });30        });31    });32 33    describe('async - promise', function() {34        it('it should find a command named ls or xcopy', function(done){35            var commandToUse = 'ls'36            if (isUsingWindows) {37                commandToUse = 'xcopy'38            }39 40            commandExists(commandToUse)41            .then(function(command) {42                expect(command).to.be(commandToUse);43                done();44            });45        });46 47        it('it should not find a command named fdsafdsafdsafdsafdsa', function(done){48            commandExists('fdsafdsafdsafdsafdsa')49            .then(function() {50                // We should not execute this line.51                expect(true).to.be(false);52            })53            .catch(function() {54                done();55            });56        });57    });58 59    describe('sync', function() {60        it('it should find a command named ls or xcopy', function(){61            var commandToUse = 'ls'62            if (isUsingWindows) {63                commandToUse = 'xcopy'64            }65            expect(commandExistsSync(commandToUse)).to.be(true);66        });67 68        it('it should not find a command named fdsafdsafdsafdsafdsa', function(){69            expect(commandExistsSync('fdsafdsafdsafdsafdsa')).to.be(false);70        });71 72        it('it should not find a command named ls or xcopy prefixed with some nonsense', function(){73            var commandToUse = 'fdsafdsa ls'74            if (isUsingWindows) {75                commandToUse = 'fdsafdsaf xcopy'76            }77            expect(commandExistsSync(commandToUse)).to.be(false);78        });79 80        it('it should not execute some nefarious code', function(){81            expect(commandExistsSync('ls; touch /tmp/foo0')).to.be(false);82        });83 84        it('it should not execute some nefarious code', function(){85            expect(commandExistsSync('ls touch /tmp/foo0')).to.be(false);86        });87    });88 89    describe('local file', function() {90        it('it should report false if there is a non-executable file with that name', function(done) {91            var commandToUse = 'test/non-executable-script.js'92            commandExists(commandToUse)93                .then(function(command){94                    // We should not execute this line.95                    expect(true).to.be(false);96                }).catch(function(err){97                    expect(err).to.be(null);98                    done();99                });100        });101 102 103        if (!isUsingWindows) {104            it('it should report true if there is an executable file with that name', function(done) {105                var commandToUse = 'test/executable-script.js'106                commandExists(commandToUse)107                    .then(function(command){108                        // We should not execute this line.109                        expect(command).to.be(commandToUse);110                        done();111                    });112            });113        }114 115        if (isUsingWindows) {116            it('it should report true if there is an executable file with that name', function(done) {117                var commandToUse = 'test\\executable-script.cmd'118                commandExists(commandToUse)119                    .then(function(command){120                        expect(command).to.be(commandToUse);121                        done();122                    });123            });124 125            it('it should report false if there is a double quotation mark in the file path', function() {126                var commandToUse = 'test\\"executable-script.cmd'127                expect(commandExists.sync(commandToUse)).to.be(false);128            });129        }130    });131 132    describe('absolute path', function() {133        it('it should report true if there is a command with that name in absolute path', function(done) {134            var commandToUse = resolve('test/executable-script.js');135            commandExists(commandToUse)136            .then(function(command){137                expect(command).to.be(commandToUse);138                done();139            });140        });141        142        it('it should report false if there is not a command with that name in absolute path', function() {143            var commandToUse = resolve('executable-script.js');144            expect(commandExists.sync(commandToUse)).to.be(false);145        });146    });147});148