|
1 | 1 | require("spec.helpers") -- for kong.log |
2 | 2 | local declarative = require "kong.db.declarative" |
3 | 3 | local conf_loader = require "kong.conf_loader" |
| 4 | +local uuid = require "kong.tools.uuid" |
| 5 | + |
| 6 | +local pl_file = require "pl.file" |
4 | 7 |
|
5 | 8 | local null = ngx.null |
6 | 9 |
|
@@ -64,4 +67,55 @@ keyauth_credentials: |
64 | 67 | end) |
65 | 68 | end) |
66 | 69 |
|
| 70 | + it("parse nested entities correctly", function () |
| 71 | + -- This regression test case is to make sure that when a |
| 72 | + -- "raw" input of declarative config is given, the dc parser |
| 73 | + -- can generate correct UUIDs for those nested entites. |
| 74 | + -- When the declarative config parser tries to flatten the |
| 75 | + -- config input, the input will be running agains the |
| 76 | + -- declarative_config schema validation. But some input |
| 77 | + -- might lacks required fieds(such as UUIDS) and their |
| 78 | + -- relationships are declared by nesting objects. In such |
| 79 | + -- cases the declarative config parser must generate necessary |
| 80 | + -- fields for all the objects(known entities) inside the config. |
| 81 | + -- This test case is to make sure that the parser can generate |
| 82 | + -- correct UUIDs for nested entities. What's more, it also makes |
| 83 | + -- sure that UUID generation are not influenced by the `transient` |
| 84 | + -- field(used as a backref to foreign objects) configured inside |
| 85 | + -- the schema. |
| 86 | + -- |
| 87 | + -- See https://github.com/Kong/kong/pull/14082 for more details. |
| 88 | + local cluster_cert_content = assert(pl_file.read("spec/fixtures/kong_clustering.crt")) |
| 89 | + local cluster_key_content = assert(pl_file.read("spec/fixtures/kong_clustering.key")) |
| 90 | + local cert_id = uuid.uuid() |
| 91 | + local sni_id = uuid.uuid() |
| 92 | + local dc = declarative.new_config(conf_loader()) |
| 93 | + local entities, err = dc:parse_table( |
| 94 | + { |
| 95 | + _format_version = "3.0", |
| 96 | + certificates = { { |
| 97 | + cert = cluster_cert_content, |
| 98 | + id = cert_id, |
| 99 | + key = cluster_key_content, |
| 100 | + snis = { { |
| 101 | + id = sni_id, |
| 102 | + name = "alpha.example" |
| 103 | + } } |
| 104 | + } }, |
| 105 | + consumers = { { |
| 106 | + basicauth_credentials = { { |
| 107 | + password = "qwerty", |
| 108 | + username = "qwerty" |
| 109 | + } }, |
| 110 | + username = "consumerA" |
| 111 | + } } |
| 112 | + } |
| 113 | + ) |
| 114 | + |
| 115 | + assert.is_nil(err) |
| 116 | + assert.is_table(entities) |
| 117 | + assert.is_not_nil(entities.snis) |
| 118 | + assert.same('alpha.example', entities.certificates[cert_id].snis[1].name) |
| 119 | + end) |
| 120 | + |
67 | 121 | end) |
0 commit comments