Mercurial > prosody-hg
annotate spec/util_argparse_spec.lua @ 13587:fdb2e0568cf8
mod_authz_internal: Make 'prosody:guest' default role for all unknown JIDs
This fixes an issue where e.g. remote users or even other users on the server
were unable to list MUC rooms.
We want to define a permission to list MUC rooms, but we want it to be
available to everyone by default (the traditional behaviour).
prosody:guest is the lowest role we have. I ran a quick check and it isn't
really used for anything right now that would be concerning.
It was originally designed for anonymous logins. I think it's safe to treat
remote JIDs as equivalent, since we have no trust relationship with anonymous
users either.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 07 Jan 2025 14:41:32 +0000 |
| parents | 4ee9a912ceea |
| children | 48c056c10e5a |
| rev | line source |
|---|---|
| 11843 | 1 describe("parse", function() |
| 2 local parse | |
| 3 setup(function() parse = require"util.argparse".parse; end); | |
| 4 | |
| 5 it("works", function() | |
| 6 -- basic smoke test | |
| 7 local opts = parse({ "--help" }); | |
| 8 assert.same({ help = true }, opts); | |
| 9 end); | |
| 10 | |
| 11 it("returns if no args", function() assert.same({}, parse({})); end); | |
| 12 | |
| 13 it("supports boolean flags", function() | |
| 14 local opts, err = parse({ "--foo"; "--no-bar" }); | |
| 15 assert.falsy(err); | |
| 16 assert.same({ foo = true; bar = false }, opts); | |
| 17 end); | |
| 18 | |
| 19 it("consumes input until the first argument", function() | |
| 20 local arg = { "--foo"; "bar"; "--baz" }; | |
| 21 local opts, err = parse(arg); | |
| 22 assert.falsy(err); | |
|
12477
cc84682b8429
util.argparse: Revise 553c6204fe5b with a different approach
Matthew Wild <mwild1@gmail.com>
parents:
11845
diff
changeset
|
23 assert.same({ foo = true, "bar", "--baz" }, opts); |
| 11843 | 24 assert.same({ "bar"; "--baz" }, arg); |
| 25 end); | |
| 26 | |
| 27 it("expands short options", function() | |
| 28 local opts, err = parse({ "--foo"; "-b" }, { short_params = { b = "bar" } }); | |
| 29 assert.falsy(err); | |
| 30 assert.same({ foo = true; bar = true }, opts); | |
| 31 end); | |
| 32 | |
| 33 it("supports value arguments", function() | |
| 34 local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { value_params = { foo = true; bar = true } }); | |
| 35 assert.falsy(err); | |
| 36 assert.same({ foo = "bar"; baz = "moo" }, opts); | |
| 37 end); | |
| 38 | |
| 39 it("demands values for value params", function() | |
| 40 local opts, err, where = parse({ "--foo" }, { value_params = { foo = true } }); | |
| 41 assert.falsy(opts); | |
| 42 assert.equal("missing-value", err); | |
| 43 assert.equal("--foo", where); | |
| 44 end); | |
| 45 | |
|
11845
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
46 it("reports where the problem is", function() |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
47 local opts, err, where = parse({ "-h" }); |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
48 assert.falsy(opts); |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
49 assert.equal("param-not-found", err); |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
50 assert.equal("-h", where, "returned where"); |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
51 end); |
|
97c1399720c2
util.argparse: Add test for #1691
Kim Alvefur <zash@zash.se>
parents:
11843
diff
changeset
|
52 |
|
13160
4ee9a912ceea
util.argparse: Add support for repeatable parameters
Kim Alvefur <zash@zash.se>
parents:
12477
diff
changeset
|
53 it("supports array arguments", function () |
|
4ee9a912ceea
util.argparse: Add support for repeatable parameters
Kim Alvefur <zash@zash.se>
parents:
12477
diff
changeset
|
54 local opts, err = parse({ "--item"; "foo"; "--item"; "bar" }, { array_params = { item = true } }); |
|
4ee9a912ceea
util.argparse: Add support for repeatable parameters
Kim Alvefur <zash@zash.se>
parents:
12477
diff
changeset
|
55 assert.falsy(err); |
|
4ee9a912ceea
util.argparse: Add support for repeatable parameters
Kim Alvefur <zash@zash.se>
parents:
12477
diff
changeset
|
56 assert.same({"foo","bar"}, opts.item); |
|
4ee9a912ceea
util.argparse: Add support for repeatable parameters
Kim Alvefur <zash@zash.se>
parents:
12477
diff
changeset
|
57 end) |
| 11843 | 58 end); |
