Add IpAddress middleware for #519
This commit is contained in:
parent
ab4773c3d4
commit
4352c9233d
10 changed files with 66 additions and 17 deletions
1
test.php
1
test.php
|
|
@ -62,6 +62,7 @@ function runTest(Config $config, String $file, String $category): int
|
|||
$in = $parts[$i];
|
||||
$exp = $parts[$i + 1];
|
||||
$api = new Api($config);
|
||||
$_SERVER['REMOTE_ADDR'] = 'TEST_IP';
|
||||
$out = $api->handle(Request::fromString($in));
|
||||
if ($recording) {
|
||||
$parts[$i + 1] = $out;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ $settings = [
|
|||
'authorization.recordHandler' => function ($operation, $tableName) {
|
||||
return ($tableName == 'comments') ? 'filter=message,neq,invisible' : '';
|
||||
},
|
||||
'ipAddress.tables' => 'barcodes',
|
||||
'ipAddress.columns' => 'ip_address',
|
||||
'sanitation.handler' => function ($operation, $tableName, $column, $value) {
|
||||
return is_string($value) ? strip_tags($value) : $value;
|
||||
},
|
||||
|
|
|
|||
5
tests/fixtures/blog_mysql.sql
vendored
5
tests/fixtures/blog_mysql.sql
vendored
|
|
@ -144,12 +144,13 @@ CREATE TABLE `barcodes` (
|
|||
`product_id` int(11) NOT NULL,
|
||||
`hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||
`bin` blob NOT NULL,
|
||||
`ip_address` varchar(15),
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `barcodes_product_id_fkey` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
INSERT INTO `barcodes` (`product_id`, `hex`, `bin`) VALUES
|
||||
(1, '00ff01', UNHEX('00ff01'));
|
||||
INSERT INTO `barcodes` (`product_id`, `hex`, `bin`, `ip_address`) VALUES
|
||||
(1, '00ff01', UNHEX('00ff01'), '127.0.0.1');
|
||||
|
||||
DROP TABLE IF EXISTS `kunsthåndværk`;
|
||||
CREATE TABLE `kunsthåndværk` (
|
||||
|
|
|
|||
7
tests/fixtures/blog_pgsql.sql
vendored
7
tests/fixtures/blog_pgsql.sql
vendored
|
|
@ -150,7 +150,8 @@ CREATE TABLE barcodes (
|
|||
id serial NOT NULL,
|
||||
product_id integer NOT NULL,
|
||||
hex character varying(255) NOT NULL,
|
||||
bin bytea NOT NULL
|
||||
bin bytea NOT NULL,
|
||||
ip_address character varying(15)
|
||||
);
|
||||
|
||||
--
|
||||
|
|
@ -259,8 +260,8 @@ INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES
|
|||
-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES
|
||||
(1, '00ff01', E'\\x00ff01');
|
||||
INSERT INTO "barcodes" ("product_id", "hex", "bin", "ip_address") VALUES
|
||||
(1, '00ff01', E'\\x00ff01', '127.0.0.1');
|
||||
|
||||
--
|
||||
-- Data for Name: kunsthåndværk; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
|
|
|
|||
3
tests/fixtures/blog_sqlsrv.sql
vendored
3
tests/fixtures/blog_sqlsrv.sql
vendored
|
|
@ -275,6 +275,7 @@ CREATE TABLE [barcodes](
|
|||
[product_id] [int] NOT NULL,
|
||||
[hex] [nvarchar](255) NOT NULL,
|
||||
[bin] [varbinary](max) NOT NULL,
|
||||
[ip_address] [nvarchar](15),
|
||||
CONSTRAINT [barcodes_pkey] PRIMARY KEY CLUSTERED([id] ASC)
|
||||
)
|
||||
GO
|
||||
|
|
@ -350,7 +351,7 @@ GO
|
|||
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')
|
||||
GO
|
||||
|
||||
INSERT [barcodes] ([product_id], [hex], [bin]) VALUES (1, N'00ff01', 0x00ff01)
|
||||
INSERT [barcodes] ([product_id], [hex], [bin], [ip_address]) VALUES (1, N'00ff01', 0x00ff01, N'127.0.0.1')
|
||||
GO
|
||||
|
||||
INSERT [kunsthåndværk] ([id], [Umlauts ä_ö_ü-COUNT], [user_id], [invisible]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d', 1, 1, NULL)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
POST /records/barcodes
|
||||
|
||||
{"product_id":1,"hex":"","bin":""}
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 1
|
||||
|
||||
2
|
||||
===
|
||||
GET /records/barcodes/2
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 64
|
||||
|
||||
{"id":2,"product_id":1,"hex":"","bin":"","ip_address":"TEST_IP"}
|
||||
===
|
||||
PUT /records/barcodes/2
|
||||
|
||||
{"ip_address":"FAKE_IP"}
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 1
|
||||
|
||||
0
|
||||
===
|
||||
GET /records/barcodes/2
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 64
|
||||
|
||||
{"id":2,"product_id":1,"hex":"","bin":"","ip_address":"TEST_IP"}
|
||||
===
|
||||
DELETE /records/barcodes/2
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 1
|
||||
|
||||
1
|
||||
|
|
@ -2,6 +2,6 @@ GET /columns
|
|||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 2645
|
||||
Content-Length: 2712
|
||||
|
||||
{"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}]}]}
|
||||
{"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,6 +2,6 @@ GET /columns/barcodes
|
|||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 216
|
||||
Content-Length: 283
|
||||
|
||||
{"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":"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}]}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ GET /columns/barcodes2
|
|||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 217
|
||||
Content-Length: 284
|
||||
|
||||
{"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":"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}]}
|
||||
===
|
||||
PUT /columns/barcodes2
|
||||
|
||||
|
|
@ -30,6 +30,6 @@ GET /columns/barcodes
|
|||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 216
|
||||
Content-Length: 283
|
||||
|
||||
{"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":"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}]}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
POST /columns
|
||||
|
||||
{"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":"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}]}
|
||||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
|
|
@ -12,9 +12,9 @@ GET /columns/barcodes2
|
|||
===
|
||||
200
|
||||
Content-Type: application/json
|
||||
Content-Length: 217
|
||||
Content-Length: 284
|
||||
|
||||
{"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":"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}]}
|
||||
===
|
||||
DELETE /columns/barcodes2
|
||||
===
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue