Sfoglia il codice sorgente

Add IpAddress middleware for #519

Maurits van der Schee 5 anni fa
parent
commit
4352c9233d

+ 1
- 0
test.php Vedi File

62
         $in = $parts[$i];
62
         $in = $parts[$i];
63
         $exp = $parts[$i + 1];
63
         $exp = $parts[$i + 1];
64
         $api = new Api($config);
64
         $api = new Api($config);
65
+        $_SERVER['REMOTE_ADDR'] = 'TEST_IP';
65
         $out = $api->handle(Request::fromString($in));
66
         $out = $api->handle(Request::fromString($in));
66
         if ($recording) {
67
         if ($recording) {
67
             $parts[$i + 1] = $out;
68
             $parts[$i + 1] = $out;

+ 2
- 0
tests/config/base.php Vedi File

19
     'authorization.recordHandler' => function ($operation, $tableName) {
19
     'authorization.recordHandler' => function ($operation, $tableName) {
20
         return ($tableName == 'comments') ? 'filter=message,neq,invisible' : '';
20
         return ($tableName == 'comments') ? 'filter=message,neq,invisible' : '';
21
     },
21
     },
22
+    'ipAddress.tables' => 'barcodes',
23
+    'ipAddress.columns' => 'ip_address',
22
     'sanitation.handler' => function ($operation, $tableName, $column, $value) {
24
     'sanitation.handler' => function ($operation, $tableName, $column, $value) {
23
         return is_string($value) ? strip_tags($value) : $value;
25
         return is_string($value) ? strip_tags($value) : $value;
24
     },
26
     },

+ 3
- 2
tests/fixtures/blog_mysql.sql Vedi File

144
   `product_id` int(11) NOT NULL,
144
   `product_id` int(11) NOT NULL,
145
   `hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
145
   `hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
146
   `bin` blob NOT NULL,
146
   `bin` blob NOT NULL,
147
+  `ip_address` varchar(15),
147
   PRIMARY KEY (`id`),
148
   PRIMARY KEY (`id`),
148
   CONSTRAINT `barcodes_product_id_fkey` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
149
   CONSTRAINT `barcodes_product_id_fkey` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
149
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
150
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
150
 
151
 
151
-INSERT INTO `barcodes` (`product_id`, `hex`, `bin`) VALUES
152
-(1, '00ff01', UNHEX('00ff01'));
152
+INSERT INTO `barcodes` (`product_id`, `hex`, `bin`, `ip_address`) VALUES
153
+(1, '00ff01', UNHEX('00ff01'), '127.0.0.1');
153
 
154
 
154
 DROP TABLE IF EXISTS `kunsthåndværk`;
155
 DROP TABLE IF EXISTS `kunsthåndværk`;
155
 CREATE TABLE `kunsthåndværk` (
156
 CREATE TABLE `kunsthåndværk` (

+ 4
- 3
tests/fixtures/blog_pgsql.sql Vedi File

150
     id serial NOT NULL,
150
     id serial NOT NULL,
151
     product_id integer NOT NULL,
151
     product_id integer NOT NULL,
152
     hex character varying(255) NOT NULL,
152
     hex character varying(255) NOT NULL,
153
-    bin bytea NOT NULL
153
+    bin bytea NOT NULL,
154
+    ip_address character varying(15)
154
 );
155
 );
155
 
156
 
156
 --
157
 --
259
 -- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres
260
 -- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres
260
 --
261
 --
261
 
262
 
262
-INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES
263
-(1,	'00ff01', E'\\x00ff01');
263
+INSERT INTO "barcodes" ("product_id", "hex", "bin", "ip_address") VALUES
264
+(1,	'00ff01', E'\\x00ff01',	'127.0.0.1');
264
 
265
 
265
 --
266
 --
266
 -- Data for Name: kunsthåndværk; Type: TABLE DATA; Schema: public; Owner: postgres
267
 -- Data for Name: kunsthåndværk; Type: TABLE DATA; Schema: public; Owner: postgres

+ 2
- 1
tests/fixtures/blog_sqlsrv.sql Vedi File

275
 	[product_id] [int] NOT NULL,
275
 	[product_id] [int] NOT NULL,
276
 	[hex] [nvarchar](255) NOT NULL,
276
 	[hex] [nvarchar](255) NOT NULL,
277
 	[bin] [varbinary](max) NOT NULL,
277
 	[bin] [varbinary](max) NOT NULL,
278
+	[ip_address] [nvarchar](15),
278
 	CONSTRAINT [barcodes_pkey] PRIMARY KEY CLUSTERED([id] ASC)
279
 	CONSTRAINT [barcodes_pkey] PRIMARY KEY CLUSTERED([id] ASC)
279
 )
280
 )
280
 GO
281
 GO
350
 INSERT [products] ([name], [price], [properties], [created_at]) VALUES (N'Calculator', N'23.01', N'<root type="object"><depth type="boolean">false</depth><model type="string">TRX-120</model><width type="number">100</width><height type="null" /></root>', '1970-01-01 01:01:01')
351
 INSERT [products] ([name], [price], [properties], [created_at]) VALUES (N'Calculator', N'23.01', N'<root type="object"><depth type="boolean">false</depth><model type="string">TRX-120</model><width type="number">100</width><height type="null" /></root>', '1970-01-01 01:01:01')
351
 GO
352
 GO
352
 
353
 
353
-INSERT [barcodes] ([product_id], [hex], [bin]) VALUES (1, N'00ff01', 0x00ff01)
354
+INSERT [barcodes] ([product_id], [hex], [bin], [ip_address]) VALUES (1, N'00ff01', 0x00ff01, N'127.0.0.1')
354
 GO
355
 GO
355
 
356
 
356
 INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL)
357
 INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL)

+ 43
- 0
tests/functional/001_records/080_add_barcode_with_ip_address.log Vedi File

1
+POST /records/barcodes
2
+
3
+{"product_id":1,"hex":"","bin":""}
4
+===
5
+200
6
+Content-Type: application/json
7
+Content-Length: 1
8
+
9
+2
10
+===
11
+GET /records/barcodes/2
12
+===
13
+200
14
+Content-Type: application/json
15
+Content-Length: 64
16
+
17
+{"id":2,"product_id":1,"hex":"","bin":"","ip_address":"TEST_IP"}
18
+===
19
+PUT /records/barcodes/2
20
+
21
+{"ip_address":"FAKE_IP"}
22
+===
23
+200
24
+Content-Type: application/json
25
+Content-Length: 1
26
+
27
+0
28
+===
29
+GET /records/barcodes/2
30
+===
31
+200
32
+Content-Type: application/json
33
+Content-Length: 64
34
+
35
+{"id":2,"product_id":1,"hex":"","bin":"","ip_address":"TEST_IP"}
36
+===
37
+DELETE /records/barcodes/2
38
+===
39
+200
40
+Content-Type: application/json
41
+Content-Length: 1
42
+
43
+1

+ 2
- 2
tests/functional/003_columns/001_get_database.log Vedi File

2
 ===
2
 ===
3
 200
3
 200
4
 Content-Type: application/json
4
 Content-Type: application/json
5
-Content-Length: 2645
5
+Content-Length: 2712
6
 
6
 
7
-{"tables":[{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]},{"name":"categories","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","type":"table","columns":[{"name":"id","type":"bigint","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255},{"name":"category_id","type":"integer","fk":"categories"}]},{"name":"countries","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp","nullable":true},{"name":"visitors","type":"bigint","nullable":true}]},{"name":"kunsthåndværk","type":"table","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"},{"name":"user_id","type":"integer","fk":"users"}]},{"name":"nopk","type":"table","columns":[{"name":"id","type":"varchar","length":36}]},{"name":"post_tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tag_usage","type":"view","columns":[{"name":"name","type":"varchar","length":255},{"name":"count","type":"bigint"}]},{"name":"tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}
7
+{"tables":[{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]},{"name":"categories","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","type":"table","columns":[{"name":"id","type":"bigint","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255},{"name":"category_id","type":"integer","fk":"categories"}]},{"name":"countries","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp","nullable":true},{"name":"visitors","type":"bigint","nullable":true}]},{"name":"kunsthåndværk","type":"table","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"},{"name":"user_id","type":"integer","fk":"users"}]},{"name":"nopk","type":"table","columns":[{"name":"id","type":"varchar","length":36}]},{"name":"post_tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tag_usage","type":"view","columns":[{"name":"name","type":"varchar","length":255},{"name":"count","type":"bigint"}]},{"name":"tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}

+ 2
- 2
tests/functional/003_columns/002_get_barcodes_table.log Vedi File

2
 ===
2
 ===
3
 200
3
 200
4
 Content-Type: application/json
4
 Content-Type: application/json
5
-Content-Length: 216
5
+Content-Length: 283
6
 
6
 
7
-{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
7
+{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]}

+ 4
- 4
tests/functional/003_columns/008_update_barcodes_table.log Vedi File

12
 ===
12
 ===
13
 200
13
 200
14
 Content-Type: application/json
14
 Content-Type: application/json
15
-Content-Length: 217
15
+Content-Length: 284
16
 
16
 
17
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
17
+{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]}
18
 ===
18
 ===
19
 PUT /columns/barcodes2
19
 PUT /columns/barcodes2
20
 
20
 
30
 ===
30
 ===
31
 200
31
 200
32
 Content-Type: application/json
32
 Content-Type: application/json
33
-Content-Length: 216
33
+Content-Length: 283
34
 
34
 
35
-{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
35
+{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]}

+ 3
- 3
tests/functional/003_columns/010_create_barcodes_table.log Vedi File

1
 POST /columns
1
 POST /columns
2
 
2
 
3
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
3
+{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]}
4
 ===
4
 ===
5
 200
5
 200
6
 Content-Type: application/json
6
 Content-Type: application/json
12
 ===
12
 ===
13
 200
13
 200
14
 Content-Type: application/json
14
 Content-Type: application/json
15
-Content-Length: 217
15
+Content-Length: 284
16
 
16
 
17
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
17
+{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"},{"name":"ip_address","type":"varchar","length":15,"nullable":true}]}
18
 ===
18
 ===
19
 DELETE /columns/barcodes2
19
 DELETE /columns/barcodes2
20
 ===
20
 ===

Loading…
Annulla
Salva