summaryrefslogtreecommitdiff
path: root/lib/model/tests/identifier.t
blob: 0b737c7f96c75949e58d6897c8c7869cd952fa79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Test the [Model.Identifier] module: validation of the names, their quoted SQL
form, the predefined columns and the composite names used for the dedicated
tables of multivalued fields.

Valid identifiers are printed in their quoted SQL form:

  $ tests --identifier check entity user-details user_type_list
  "entity"
  "user-details"
  "user_type_list"

Invalid identifiers are rejected: the empty string, and any character outside
letters, digits, underscore and hyphen — in particular the double quote (which
could break out of a quoted identifier) and the dot (reserved for the composite
table names):

  $ tests --identifier check 'evil"; DROP TABLE entity;--' foo.bar ''
  invalid: "evil"; DROP TABLE entity;--"
  invalid: "foo.bar"
  invalid: ""

The fixed columns of the generated schema are predefined:

  $ tests --identifier predefined
  id = "id"
  parent = "parent"
  target = "target"

A composite name is built from two valid identifiers:

  $ tests --identifier dot entity references
  "entity.references"

An invalid part is rejected when building a composite name:

  $ tests --identifier dot 'bad"name' ref
  Fatal error: exception Model__Identifier.Invalid("bad\"name")
  [2]