Commit graph

605 commits

Author SHA1 Message Date
Kim Alvefur
0ed2d38edf core.storagemanager: Fix tests by removing an assert that upset luarocks
Not sure why but this assert() caused a stack overflow in luarocks
2025-03-19 16:15:52 +01:00
Matthew Wild
06994f0bc1 util.argparse: Fix bug (regression?) in argument parsing with --foo=bar
After recent changes, '--foo bar' was working, but '--foo=bar' was not. The
test had a typo (?) (bar != baz) and because util.argparse is not strict by
default, the typo was not caught.

The typo caused the code to take a different path, and bypassed the buggy
handling of --foo=bar options.

I've preserved the existing test (typo and all!) because it's still an
interesting test, and ensures no unintended behaviour changes compared to the
old code.

However I've added a new variant of the test, with strict mode enabled and the
typo fixed. This test failed due to the bug, and this commit introduces a fix.
2025-03-11 18:27:36 +00:00
Matthew Wild
43be6cb1c6 util.argparse: Add strict mode + tests 2025-02-17 18:24:23 +00:00
Kim Alvefur
2f37c443b8 core.configmanager: Add ways to read config values from files
Inspired by something MattJ said

Allows retrieving config values from files which are expected to be
relative to the config directory, extending on the ENV_ method of
retrieving config values from outside the config file.

- FileLine retrieves the first line, stripping any trailing newline
- FileContents reads the whole file
- FileLines reads lines into an array
2025-01-16 15:05:00 +01:00
Kim Alvefur
885fde62be util.stanza: Handle Clark notation for attributes in :find() 2024-11-17 13:40:20 +01:00
Kim Alvefur
00584c4d61 util.stanza: Handle namespace prefixes for attributes in :find()
More correct handling of namespaces here.

This works with both prefixes from the parser and hacky .attr["foo:bar"]
2024-11-17 12:35:51 +01:00
Matthew Wild
c9cc6f4b67 util.queue: tests: Add test for :replace() method 2024-11-12 11:25:49 +00:00
Kim Alvefur
9005d35b48 util.pubsub: Add method returning subset of config as metadata
Allows granting read only access to other sets of users using a separate
access control capability, which makes sense as some properties may be
intended to be public but read-only.
2024-11-08 02:11:00 +01:00
Kim Alvefur
77833e7394 scansion: Remove publisher attribute from bookmarks2 tests
Seems exposing publisher is not enabled in mod_pep, but then it'll be
the user themselves most of the time
2024-10-31 17:18:43 +01:00
Kim Alvefur
12b787430a scansion: Import XEP-0402 test from prosody-modules rev 2c6b14207271
This corresponds to the file mod_bookmarks2/tests/bookmarks2.scs
2024-10-31 17:22:38 +01:00
Stephen Paul Weber
d477528e67 util.crypto: Add more ECC methods
pkey_meth_derive: to derive a shared symmetric key from two ECC keys
pkey_meth_public_raw: to get the raw form of the public key
import_public_ec_raw: to import the raw form of the public key
generate_p256_keypair: key generation for the P-256 curve
2024-10-29 09:15:50 -05:00
Kim Alvefur
25754509f4 util.pubsub: Fix test to account for not using util.error 2024-10-29 15:05:14 +01:00
Kim Alvefur
73b512d3a6 util.error: Use is_error() instead of is_err() everywhere
Continuation of 4b39691a274e
2024-10-29 14:10:02 +01:00
Kim Alvefur
8a96854733 util.xtemplate: Fix error on applying each() to zero stanzas 2024-07-11 15:04:29 +02:00
Kim Alvefur
5915d6fbcd Merge 0.12->trunk 2024-06-12 23:20:48 +02:00
Kim Alvefur
935de9b5e7 scansion: Add roster groups setting to pubsub form in tests 2024-06-12 23:14:55 +02:00
Kim Alvefur
11bc995c0b scansion: Enable blocklist compat during tests to fix CI 2024-06-12 23:00:24 +02:00
Matthew Wild
876162b9cf util.bit53: Add bnot() method 2024-03-01 17:22:29 +00:00
Matthew Wild
965d69763c util.strbitop: Remove unused import in tests 2024-02-23 12:13:06 +00:00
Matthew Wild
7f748556a2 util.strbitop: Add common_prefix_bits() method
This returns the number of bits that two strings have in common. It is
significantly more efficient than similar calculations in Lua.
2024-02-23 12:08:37 +00:00
Matthew Wild
1606675762 util.ip: Add another test case for match() and commonPrefixLength() 2024-02-23 12:03:31 +00:00
Matthew Wild
81cb34ef50 util.strbitop: Rename spec file to correct name so tests actually run 2024-02-23 11:59:45 +00:00
Kim Alvefur
ddd479afe2 util.rfc6724: Remove, unused since introduction of Happy Eyeballs
It was mainly used to determine whether to try IPv6 or IPv4 first,
following the rules for this in the RFC.

Now we always try IPv6 and IPv4 at roughly the same time, thus there no
need to carry these rules.
2024-02-22 19:46:52 +01:00
Kim Alvefur
4ca636bb7e mod_disco: Advertise disco#info and #items on bare JIDs to fix #1664
Having to add these in *there* places seems less than ideal.

I would also think that advertising disco#info is a bit redundant, since
it is a requirement for everything in XMPP and if it was missing you
would get an error back.
2023-12-17 18:55:14 +01:00
Kim Alvefur
674b91b82b net.http.parser: Reject overlarge header section earlier
This case would eventually be rejected by the buffer size limit.
2023-08-23 12:18:34 +02:00
Kim Alvefur
0fa9d6be37 util.array: Fix new() library function
Backport of ffe4adbd2af9 since new was added in the 0.12 branch
2023-07-22 16:31:05 +02:00
Matthew Wild
87ee5a2300 net.http.parser: Fix off-by-one error in chunk parser 2023-02-17 17:01:19 +00:00
Matthew Wild
0fd88a07a4 net.http.parser: Improve handling of responses without content-length
This ensures that we support responses without a content-length header, and
allow streaming them through the streaming handler interface. An example of
such a response would be Server-Sent Events streams.
2023-02-09 22:57:32 +00:00
Matthew Wild
d4daf40caa util.json: Accept empty arrays with whitespace (fixes #1782) 2022-11-04 12:26:10 +00:00
Kim Alvefur
c617f27a54 util.jsonschema: Ignore test case for JavaScript specific detail
Also touching on how arrays are indistinguishable from tables in Lua
2022-10-09 15:24:30 +02:00
Kim Alvefur
8f850047e3 util.jsonschema: Ignore some further test cases for URI references
Full-URI references are not implemented
2022-10-09 15:24:26 +02:00
Kim Alvefur
1e74554e20 util.jsonschema: Sort test cases to skip
Piped trough `sort -g`
2022-10-09 14:58:07 +02:00
Kim Alvefur
3ee6df83b0 storage tests: Add test for the archive:summary API
Passes with memory, internal, sqlite
Fails with postgres as in #1766
2022-07-22 18:32:45 +02:00
Kim Alvefur
96301b2229 mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
This is happens if the account is new and doesn't have any bookmarks
yet, which is not a problem.

Rarely seen since most clients currently use the older version of
XEP-0084 stored in XEP-0049 rather than in PEP, but at least one
(Converse.js )does.

One scenario in which this would show up often is with Converse.js as a
guest chat using anonymous authentication, where all "accounts" would
always be new and not have any bookmarks. This scenario probably does
not need to have mod_bookmarks at all, but if enabled globally it would
likely become loaded onto the VirtualHost unless explicitly disabled.
2022-07-26 23:44:33 +02:00
Kim Alvefur
89359b70dc util.datamapper: Improve handling of schemas with non-obvious "type"
The JSON Schema specification says that schemas are objects or booleans,
and that the 'type' property is optional and can be an array.

This module previously allowed bare type names as schemas and did not
really handle booleans.

It now handles missing 'type' properties and boolean 'true' as a schema.
Objects and arrays are guessed based on the presence of 'properties' or
'items' field.
2022-07-08 17:32:48 +02:00
Kim Alvefur
e700edc50f util.jsonschema: Fix validation to not assume presence of "type" field
MattJ reported a curious issue where validation did not work as
expected. Primarily that the "type" field was expected to be mandatory,
and thus leaving it out would result in no checks being performed.
This was likely caused by misreading during initial development.

Spent some time testing against
https://github.com/json-schema-org/JSON-Schema-Test-Suite.git and
discovered a multitude of issues, far too many to bother splitting into
separate commits.

More than half of them fail. Many because of features not implemented,
which have been marked NYI. For example, some require deep comparisons
e.g. when objects or arrays are present in enums fields.

Some because of quirks with how Lua differs from JavaScript, e.g. no
distinct array or object types. Tests involving fractional floating
point numbers. We're definitely not going to follow references to remote
resources. Or deal with UTF-16 sillyness. One test asserted that 1.0 is
an integer, where Lua 5.3+ will disagree.
2022-07-08 14:38:23 +02:00
Kim Alvefur
11638f57e2 util.jsonpointer: Add basic tests
Example values from RFC 6901
2022-05-08 18:03:44 +02:00
Matthew Wild
93347db124 util.argparse: Revise 553c6204fe5b with a different approach
The second return value is (not insensibly) assumed to be an error. Instead of
returning a value there in the success case, copy the positional arguments
into the existing opts table.
2022-04-25 15:24:56 +01:00
Kim Alvefur
43351d2b54 Spelling: Fix various spelling mistakes (thanks timeless)
Words, sometimes I wonder how they even work

Maybe I missed something.
2022-03-07 00:13:56 +01:00
Matthew Wild
7b23d9d136 util.bitcompat: Add some simple tests 2022-03-04 19:48:01 +00:00
Matthew Wild
8eadf174b4 net.stun: tests: Remove stray print() from debugging 2022-03-04 16:46:47 +00:00
Matthew Wild
a6265e45a0 net.stun: Add tests for serialization/deserialization 2022-03-04 16:13:05 +00:00
Kim Alvefur
cb66977bd4 MUC: Record reason for affiliation changes and return in list (fixes #1227) 2021-08-08 18:07:17 +02:00
Kim Alvefur
c8c1482dae MUC: Test that <subject/> + <thread/> is not handled as subject change
Ref #667
Ref #1838
2024-01-23 13:00:58 +01:00
Kim Alvefur
a7799e11a9 Merge 0.12->trunk 2023-12-17 19:02:56 +01:00
Kim Alvefur
6438e929b2 scansion: Use new style for accessing Lua globals 2023-12-17 16:41:47 +01:00
Kim Alvefur
0b5df6bdac scansion: Use new prosody namespace in import 2023-12-17 16:41:27 +01:00
Kim Alvefur
30f791386b scansion: Use captures or wildcards instead of mocking time
> Mockery is one of the things I hold dear! And he's making a mockery of it!!
-- Belkar Bitterleaf
2023-12-17 16:29:03 +01:00
Kim Alvefur
251f4d3c8a util.xtemplate: Test the each template function
It iterates over childtags, so a template like {foo|each{...}} would be
equivalent to root:childtags("foo"), while a deeper query needs the bit
that becomes arguments to :childtags as an argument to each, e.g.
{foo/bar|each(baz)} would behave like
root:get_child("foo"):get_child("bar"):childtags("baz")
2023-12-16 13:47:55 +01:00
Matthew Wild
4b0463968a mod_storage_internal, tests: Fix before/after combined with the 'reverse' flag 2023-12-12 13:41:14 +00:00