Software / code / prosody
Comparison
spec/util_stanza_spec.lua @ 8599:62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 16 Mar 2018 14:51:24 +0000 |
| parent | 8598:282d544d48f4 |
| child | 8621:e3e9479d526e |
comparison
equal
deleted
inserted
replaced
| 8598:282d544d48f4 | 8599:62bfc85a53c8 |
|---|---|
| 162 assert.are.equal(r.attr.type, "error"); | 162 assert.are.equal(r.attr.type, "error"); |
| 163 assert.are.equal(#r.tags, 1); | 163 assert.are.equal(#r.tags, 1); |
| 164 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); | 164 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); |
| 165 end); | 165 end); |
| 166 end); | 166 end); |
| 167 | |
| 168 describe("#invalid", function () | |
| 169 it("name should be rejected", function () | |
| 170 assert.has_error(function () | |
| 171 st.stanza(1234); | |
| 172 end); | |
| 173 assert.has_error(function () | |
| 174 st.stanza({}); | |
| 175 end); | |
| 176 assert.has_error(function () | |
| 177 st.stanza(); | |
| 178 end); | |
| 179 assert.has_error(function () | |
| 180 st.stanza(""); | |
| 181 end); | |
| 182 assert.has_error(function () | |
| 183 st.stanza(string.char(0xC0)); | |
| 184 end); | |
| 185 assert.has_error(function () | |
| 186 st.stanza(string.char(0xF4, 0x90, 0x80, 0x80)); | |
| 187 end); | |
| 188 assert.has_error(function () | |
| 189 st.stanza("<>"); | |
| 190 end); | |
| 191 assert.has_error(function () | |
| 192 st.stanza("&"); | |
| 193 end); | |
| 194 end); | |
| 195 it("UTF-8 should be rejected", function () | |
| 196 assert.has_error(function () | |
| 197 st.stanza("tag"):text("hello "..string.char(0xF4, 0x90, 0x80, 0x80).." world"); | |
| 198 end); | |
| 199 end); | |
| 200 end); | |
| 167 end); | 201 end); |