!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/node-red/test/unit/@node-red/editor-api/lib/admin/   drwxr-xr-x
Free 13.27 GB of 57.97 GB (22.89%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     context_spec.js (9.01 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
/**
 * Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var should = require("should");
var request = require('supertest');
var express = require('express');
var bodyParser = require('body-parser');
var sinon = require('sinon');

var NR_TEST_UTILS = require("nr-test-utils");

var context = NR_TEST_UTILS.require("@node-red/editor-api/lib/admin/context");

describe("api/admin/context", function () {
    var app = undefined;

    before(function () {
        app = express();
        app.use(bodyParser.json());
        app.get("/context/:scope(global)", context.get);
        app.get("/context/:scope(global)/*", context.get);
        app.get("/context/:scope(node|flow)/:id", context.get);
        app.get("/context/:scope(node|flow)/:id/*", context.get);

        app.delete("/context/:scope(global)/*", context.delete);
        app.delete("/context/:scope(node|flow)/:id/*", context.delete);
    });

    describe("get", function () {
        var gContext = {
            default: { abc: { msg: '111', format: 'number' } },
            file: { abc: { msg: '222', format: 'number' } }
        };
        var fContext = {
            default: { bool: { msg: 'true', format: 'boolean' } },
            file: { string: { msg: 'aaaa', format: 'string[7]' } }
        };
        var nContext = { msg: "1", format: "number" };
        var stub = sinon.stub();

        before(function () {
            context.init({
                context: {
                    getValue: stub
                }
            });
        });

        afterEach(function () {
            stub.reset();
        });

        it('should call context.getValue to get global contexts', function (done) {
            stub.returns(Promise.resolve(gContext));
            request(app)
                .get('/context/global')
                .set('Accept', 'application/json')
                .expect(200)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'global');
                    stub.args[0][0].should.have.property('id', undefined);
                    stub.args[0][0].should.have.property('key', undefined);
                    stub.args[0][0].should.have.property('store', undefined);
                    var body = res.body;
                    body.should.eql(gContext);
                    done();
                });
        });

        it('should call context.getValue to get flow contexts', function (done) {
            stub.returns(Promise.resolve(fContext));
            request(app)
                .get('/context/flow/1234/')
                .set('Accept', 'application/json')
                .expect(200)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'flow');
                    stub.args[0][0].should.have.property('id', '1234');
                    stub.args[0][0].should.have.property('key', undefined);
                    stub.args[0][0].should.have.property('store', undefined);
                    var body = res.body;
                    body.should.eql(fContext);
                    done();
                });
        });

        it('should call context.getValue to get a node context', function (done) {
            stub.returns(Promise.resolve(nContext));
            request(app)
                .get('/context/node/5678/foo?store=file')
                .set('Accept', 'application/json')
                .expect(200)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'node');
                    stub.args[0][0].should.have.property('id', '5678');
                    stub.args[0][0].should.have.property('key', 'foo');
                    stub.args[0][0].should.have.property('store', 'file');
                    var body = res.body;
                    body.should.eql(nContext);
                    done();
                });
        });

        it('should handle error which context.getValue causes', function (done) {
            var stubbedResult = Promise.reject('error');
            stubbedResult.catch(function() {});
            stub.returns(stubbedResult);
            request(app)
                .get('/context/global')
                .set('Accept', 'application/json')
                .expect(400)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    res.body.should.has.a.property('code', 'unexpected_error');
                    res.body.should.has.a.property('message', 'error');
                    done();
                });
        });
    });

    describe("delete", function () {
        var stub = sinon.stub();

        before(function () {
            context.init({
                context: {
                    delete: stub
                }
            });
        });

        afterEach(function () {
            stub.reset();
        });

        it('should call context.delete to delete a global context', function (done) {
            stub.returns(Promise.resolve());
            request(app)
                .delete('/context/global/abc?store=default')
                .expect(204)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'global');
                    stub.args[0][0].should.have.property('id', undefined);
                    stub.args[0][0].should.have.property('key', 'abc');
                    stub.args[0][0].should.have.property('store', 'default');
                    done();
                });
        });

        it('should call context.delete to delete a flow context', function (done) {
            stub.returns(Promise.resolve());
            request(app)
                .delete('/context/flow/1234/abc?store=file')
                .expect(204)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'flow');
                    stub.args[0][0].should.have.property('id', '1234');
                    stub.args[0][0].should.have.property('key', 'abc');
                    stub.args[0][0].should.have.property('store', 'file');
                    done();
                });
        });

        it('should call context.delete to delete a node context', function (done) {
            stub.returns(Promise.resolve());
            request(app)
                .delete('/context/node/5678/foo?store=file')
                .expect(204)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    stub.args[0][0].should.have.property('user', undefined);
                    stub.args[0][0].should.have.property('scope', 'node');
                    stub.args[0][0].should.have.property('id', '5678');
                    stub.args[0][0].should.have.property('key', 'foo');
                    stub.args[0][0].should.have.property('store', 'file');
                    done();
                });
        });

        it('should handle error which context.delete causes', function (done) {
            var stubbedResult = Promise.reject('error');
            stubbedResult.catch(function() {});
            stub.returns(stubbedResult);
            request(app)
                .delete('/context/global/abc?store=default')
                .expect(400)
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }
                    res.body.should.has.a.property('code', 'unexpected_error');
                    res.body.should.has.a.property('message', 'error');
                    done();
                });
        });
    });
});

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.005 ]--