| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
import cockpit from "cockpit"; |
| 3 |
import QUnit from "qunit-tests"; |
| 4 |
|
| 5 |
QUnit.test("load user info", async assert => { |
| 6 |
const dbus = cockpit.dbus(null, { bus: "internal" }); |
| 7 |
const [user] = await dbus.call("/user", "org.freedesktop.DBus.Properties", |
| 8 |
"GetAll", ["cockpit.User"], { type: "s" }); |
| 9 |
assert.ok(user.Name !== undefined, "has Name"); |
| 10 |
assert.equal(user.Name.t, "s", "string Name"); |
| 11 |
assert.ok(user.Full !== undefined, "has Full name"); |
| 12 |
assert.equal(user.Full.t, "s", "string Full"); |
| 13 |
assert.ok(user.Shell !== undefined, "has Shell"); |
| 14 |
assert.equal(user.Home.t, "s", "type Home"); |
| 15 |
assert.equal(user.Home.v.indexOf("/"), 0, "Home starts with slash"); |
| 16 |
assert.equal(user.Groups.t, "as", "type Groups"); |
| 17 |
}); |
| 18 |
|
| 19 |
QUnit.test("user object", async assert => { |
| 20 |
const user = await cockpit.user(); |
| 21 |
assert.equal(typeof user.name, "string", "user name"); |
| 22 |
assert.equal(typeof user.full_name, "string", "user full name"); |
| 23 |
assert.equal(typeof user.shell, "string", "user shell"); |
| 24 |
assert.equal(typeof user.home, "string", "user home"); |
| 25 |
assert.equal(typeof user.id, "number", "user id"); |
| 26 |
assert.equal(typeof user.gid, "number", "group id"); |
| 27 |
assert.ok(Array.isArray(user.groups), "user groups"); |
| 28 |
}); |
| 29 |
|
| 30 |
QUnit.test("user environment", async assert => { |
| 31 |
const data = await cockpit.spawn(["/bin/sh", "-c", "echo $USER~$SHELL~$HOME"]); |
| 32 |
const parts = data.split("~"); |
| 33 |
assert.ok(parts[0].length > 0, "valid $USER"); |
| 34 |
assert.ok(parts[1].length > 0, "valid $HOME"); |
| 35 |
assert.equal(parts[1].indexOf("/"), 0, "$HOME starts with slash"); |
| 36 |
assert.ok(parts[2].length > 0, "valid $SHELL"); |
| 37 |
assert.equal(parts[1].indexOf("/"), 0, "$SHELL starts with slash"); |
| 38 |
}); |
| 39 |
|
| 40 |
QUnit.start(); |