This file is indexed.

/usr/share/maas/web/static/js/tests/test_node_add.js is in maas-region-controller-min 1.5.4+bzr2294-0ubuntu1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/* Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
 * GNU Affero General Public License version 3 (see the file LICENSE).
 */

YUI({ useBrowserConsole: true }).add('maas.node_add.tests', function(Y) {

Y.log('loading maas.node_add.tests');
var namespace = Y.namespace('maas.node_add.tests');

var module = Y.maas.node_add;
var suite = new Y.Test.Suite("maas.node_add Tests");

suite.add(new Y.maas.testing.TestCase({
    name: 'test-node-add-widget-singleton',

    setUp: function() {
        // Silence io.
        var mockXhr = Y.Mock();
        Y.Mock.expect(mockXhr, {
            method: 'send',
            args: [MAAS_config.uris.nodes_handler, Y.Mock.Value.Any]
        });
        this.mockIO(mockXhr, module);
    },

    testSingletonCreation: function() {
        // module._add_node_singleton is originally null.
        Y.Assert.isNull(module._add_node_singleton);
        module.showAddNodeWidget({
            powerTypes: ['', 'value1'],
            targetNode: '#target_node',
            animate: false
            });
        // module._add_node_singleton is populated after the call to
        // module.showAddNodeWidget.
        Y.Assert.isNotNull(module._add_node_singleton);
    },

    testSingletonReCreation: function() {
        module.showAddNodeWidget({
            powerTypes: ['', 'value1'],
            targetNode: '#target_node',
            animate: false
            });
        var panel = module._add_node_singleton;

        // Make sure that a second call to showAddNodeWidget destroys
        // the old widget and creates a new one.
        var destroyed = false;
        panel.on("destroy", function(){
            destroyed = true;
        });
        module.showAddNodeWidget({
            powerTypes: ['ipmi'],
            targetNode: '#target_node',
            animate: false
            });
        Y.Assert.isTrue(destroyed);
        Y.Assert.isNotNull(module._add_node_singleton);
        Y.Assert.areNotSame(panel, namespace._add_node_singleton);
    }

}));


/* Find the add-node widget.
 */
function find_widget() {
    return module._add_node_singleton.get('srcNode');
}


/* Find the add-node form.
 */
function find_form() {
    return find_widget().one('form');
}


/* Find the hostname input field in the add-node form.
 */
function find_hostname_input() {
    return find_widget().one('#id_hostname');
}


/* Find the "Add node" button at the bottom of the add-node form.
 */
function find_add_button() {
    return find_widget().one('.add-node-button');
}


/* Find the global errors panel at the top of the add-node form.
 */
function find_global_errors() {
    return find_widget().one('.form-errors');
}


/* Set up and submit the add-node form.
 */
function submit_add_node() {
    module.showAddNodeWidget({targetNode: '#target_node', animate: false});
    find_hostname_input().set('value', 'host');
    find_add_button().simulate('click');
}


suite.add(new Y.maas.testing.TestCase({
    name: 'test-add-node-widget-add-node',

    testFormContainsArchitectureChoice: function() {
        // The generated form contains an 'architecture' field.
        module.showAddNodeWidget({targetNode: '#target_node', animate: false});
        var arch = find_form().one('#id_architecture');
        Y.Assert.isNotNull(arch);
        var arch_options = arch.all('option');
        Y.Assert.areEqual(2, arch_options.size());
     },

    testAddNodeAPICallSubmitsForm: function() {
        // The call to the API triggered by clicking on 'Add a node'
        // submits (via an API call) the panel's form.
        module.showAddNodeWidget({targetNode: '#target_node', animate: false});
        var mockXhr = new Y.Base();
        var form = find_form();
        var log = this.logIO(module);
        find_hostname_input().set('value', 'host');
        find_add_button().simulate('click');
        Y.Assert.areEqual(form, log.pop()[1].form.id);
    },

    testAddNodeAPICall: function() {
        var mockXhr = Y.Mock();
        Y.Mock.expect(mockXhr, {
            method: 'send',
            args: [MAAS_config.uris.nodes_handler, Y.Mock.Value.Any]
        });
        this.mockIO(mockXhr, module);
        module.showAddNodeWidget({targetNode: '#target_node', animate: false});
        find_hostname_input().set('value', 'host');
        find_add_button().simulate('click');
        Y.Mock.verify(mockXhr);
    },

    testAddNodeAPICallEnterPressed: function() {
        var mockXhr = Y.Mock();
        Y.Mock.expect(mockXhr, {
            method: 'send',
            args: [MAAS_config.uris.nodes_handler, Y.Mock.Value.Any]
        });
        this.mockIO(mockXhr, module);
        module.showAddNodeWidget({targetNode: '#target_node', animate: false});
        find_hostname_input().set('value', 'host');
        // Simulate 'Enter' being pressed.
        find_form().simulate("keypress", { keyCode: 13 });
        Y.Mock.verify(mockXhr);
    },

    testNodeidPopulation: function() {
        this.mockSuccess(Y.JSON.stringify({system_id: 3}), module);
        module.showAddNodeWidget({targetNode: '#target_node', animate: false});
        this.addCleanup(
            Y.bind(
                module._add_node_singleton.destroy,
                module._add_node_singleton));
        find_hostname_input().set('value', 'host');
        var button = find_add_button();

        var fired = false;
        this.registerListener(
            Y.maas.node_add.AddNodeDispatcher, module.NODE_ADDED_EVENT,
            function(e, node){
                Y.Assert.areEqual(3, node.system_id);
                fired = true;
            }
        );
        button.simulate('click');
        Y.Assert.isTrue(fired);
    },

    testValidationErrorInJSONGoesToFieldsNotGlobalErrors: function() {
        this.mockFailure('{"architecture": ["Xur."]}', module, 400);
        submit_add_node();
        Y.Assert.areEqual(
            -1, find_global_errors().get('innerHTML').search("Xur."));
        var field_label = find_widget().one('label[for="id_architecture"]');
        var error_node = field_label.next();
        Y.Assert.areNotEqual(-1, error_node.get('innerHTML').search("Xur."));
    },

    test400ErrorMessageWithPlainText: function() {
        this.mockFailure("Blergh.", module, 400);
        submit_add_node();
        var error_message = find_global_errors().get('innerHTML');
        Y.Assert.areNotEqual(-1, error_message.search("Blergh."));
    },

    testLoggedOffErrorMessage: function() {
        this.mockFailure("You are not logged in.", module, 401);
        submit_add_node();
        var error_message = find_global_errors().get('innerHTML');
        // The link to the login page is present in the error message.
        var link_position = error_message.search(MAAS_config.uris.login);
        Y.Assert.areNotEqual(-1, link_position);
    },

    testGenericErrorMessage: function() {
        this.mockFailure("Internal error.", module, 500);
        submit_add_node();
        var error_message = find_global_errors().get('innerHTML');
        Y.Assert.areNotEqual(-1, error_message.search("Internal error."));
    },

    testErrorsAreEscaped: function() {
        this.mockFailure("<huh>", module, 400);
        submit_add_node();
        var error_message = find_global_errors().get('innerHTML');
        Y.Assert.areEqual(-1, error_message.search("<huh>"));
        Y.Assert.areNotEqual(-1, error_message.search("&lt;huh&gt;"));
    }

}));

suite.add(new Y.maas.testing.TestCase({
    name: 'test-add-node-widget-add-node-admin',

    setUp: function() {
        this.setUpAdminTemplate();
    },

    setUpAdminTemplate: function() {
        // Append the snippet that will be seen by an admin user to the
        // general template.
        this.add_node_template = Y.one('#add-node').getContent();
        this.add_node_admin_snippet = Y.one('#add-node-admin').getContent();
        Y.one('#add-node').set(
            'innerHTML',
            this.add_node_template + this.add_node_admin_snippet);
    },

    tearDown: function() {
        this.tearDownAdminTemplate();
    },

    tearDownAdminTemplate: function() {
        Y.one('#add-node').set('innerHTML', this.add_node_template);
    },

    testFormContainsPowerType: function() {
        module.showAddNodeWidget({
            powerTypes: ['', 'value1'],
            targetNode: '#target_node',
            animate: false
            });
        Y.Assert.isNotNull(find_widget().one('#id_power_type'));
    },

    testPowerParameterHidden: function() {
        // The power_parameter field starts hidden.
        module.showAddNodeWidget({
            powerTypes: ['', 'value1'],
            targetNode: '#target_node',
            animate: false
            });
        Y.Assert.isTrue(
            find_widget().one('.power_parameters').hasClass('hidden'));
    },

    testPowerParameterDynamicallyLinked: function() {
        // When the option of the 'select' tag changes to a non empty
        // string, the 'power_parameters' field is shown.
        // The value1 power type has a template defined in test_node_add.html.
        module.showAddNodeWidget({
            powerTypes: ['value1'],
            targetNode: '#target_node',
            animate: false
            });
        var select = Y.one('#id_power_type');
        select.set('value', 'value1');
        select.simulate('change');
        Y.Assert.isFalse(
            find_widget().one('.power_parameters').hasClass('hidden'));
    }


}));


namespace.suite = suite;

}, '0.1', {'requires': [
    'node-event-simulate', 'test', 'maas.testing', 'maas.node_add']}
);