Annotate

spec/util_uuid_spec.lua @ 13792:4ea7bd7325be 13.0

core.portmanager: Restore use of per-host 'ssl' for SNI hosts. Fixes #1915. This was an unintentional regression, as per-host 'ssl' options became valid in 0.12 when SNI support was added for direct TLS ports. While we encourage most people to use the simpler automatic certificate selection (and it seems most do, given the overlooking of this bug), there are likely always going to be use cases for manually-configured certificates. The issue was introduced in commit 7e9ebdc75ce4 which inadvertently removed the per-host option checking for SNI.
author Kim Alvefur <zash@zash.se>
date Sat, 29 Mar 2025 22:25:19 +0100
parent 13317:e6a5f196fc1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 -- This tests the format, not the randomness
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local uuid = require "util.uuid";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 describe("util.uuid", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 describe("#generate()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 it("should work follow the UUID pattern", function()
12604
bd9e006a7a74 various: Update IETF RFC URLs for tools.ietf.org transition
Kim Alvefur <zash@zash.se>
parents: 8241
diff changeset
8 -- https://www.rfc-editor.org/rfc/rfc4122.html#section-4.4
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local pattern = "^" .. table.concat({
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 string.rep("%x", 8),
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 string.rep("%x", 4),
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 "4" .. -- version
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 string.rep("%x", 3),
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 "[89ab]" .. -- reserved bits of 1 and 0
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 string.rep("%x", 3),
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 string.rep("%x", 12),
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 }, "%-") .. "$";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 for _ = 1, 100 do
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 assert.is_string(uuid.generate():match(pattern));
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 end
13317
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
23
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
24 assert.truthy(uuid.generate() ~= uuid.generate(), "does not generate the same UUIDv4 twice")
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
25 end);
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
26 end);
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
27 describe("#v7", function()
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
28 it("should also follow the UUID pattern", function()
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
29 local pattern = "^" .. table.concat({
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
30 string.rep("%x", 8),
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
31 string.rep("%x", 4),
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
32 "7" .. -- version
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
33 string.rep("%x", 3),
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
34 "[89ab]" .. -- reserved bits of 1 and 0
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
35 string.rep("%x", 3),
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
36 string.rep("%x", 12),
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
37 }, "%-") .. "$";
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
38
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
39 local one = uuid.v7(); -- one before the loop to ensure some time passes
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
40 for _ = 1, 100 do
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
41 assert.is_string(uuid.v7():match(pattern));
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
42 end
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
43 -- one after the loop when some time should have passed
e6a5f196fc1f util.uuid: Add UUIDv7
Kim Alvefur <zash@zash.se>
parents: 12604
diff changeset
44 assert.truthy(one < uuid.v7(), "should be ordererd")
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 end);