11
11
12
12
#include " common-import.hpp"
13
13
#include " common-options.hpp"
14
+ #include " common-pg.hpp"
14
15
15
16
namespace {
16
17
@@ -38,8 +39,50 @@ struct options_slim_expire
38
39
}
39
40
};
40
41
42
+ struct options_slim_schema
43
+ {
44
+ static options_t options ()
45
+ {
46
+ auto conn = db.db ().connect ();
47
+ // Create limited user (if it doesn't exist yet),
48
+ // which we need to test that the public schema won't be touched.
49
+ // If the public schema is tried to be modified at any point, this user won't have the
50
+ // necessary permissions, and hence the test will fail.
51
+ conn.exec (R"(
52
+ DO
53
+ $$
54
+ BEGIN
55
+ IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'limited') THEN
56
+ CREATE ROLE limited LOGIN PASSWORD 'password_limited';
57
+ END IF;
58
+ END
59
+ $$;
60
+ )" );
61
+ conn.exec (" REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "
62
+ " PUBLIC, limited;" );
63
+ conn.exec (" REVOKE CREATE ON SCHEMA public FROM PUBLIC, limited;" );
64
+ conn.exec (
65
+ " CREATE SCHEMA IF NOT EXISTS myschema AUTHORIZATION limited;" );
66
+ conn.close ();
67
+ return testing::opt_t ()
68
+ .slim ()
69
+ .flex (conf_file)
70
+ .schema (" myschema" )
71
+ .user (" limited" , " password_limited" );
72
+ }
73
+ };
74
+
75
+ // Return a string with the schema name prepended to the table name.
76
+ std::string with_schema (char const *table_name, options_t const &options)
77
+ {
78
+ if (options.dbschema .empty ()) {
79
+ return {table_name};
80
+ }
81
+ return options.dbschema + " ." + table_name;
82
+ }
83
+
41
84
TEMPLATE_TEST_CASE (" updating a node" , " " , options_slim_default,
42
- options_slim_expire)
85
+ options_slim_expire, options_slim_schema )
43
86
{
44
87
options_t options = TestType::options ();
45
88
@@ -48,16 +91,16 @@ TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
48
91
49
92
auto conn = db.db ().connect ();
50
93
51
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
94
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
52
95
53
96
// give the node a tag...
54
97
options.append = true ;
55
98
REQUIRE_NOTHROW (
56
99
db.run_import (options, " n10 v2 dV x10 y10 Tamenity=restaurant\n " ));
57
100
58
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_point" ));
101
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
59
102
REQUIRE (1 ==
60
- conn.get_count (" osm2pgsql_test_point" ,
103
+ conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ,
61
104
" node_id = 10 AND tags->'amenity' = 'restaurant'" ));
62
105
63
106
SECTION (" remove the tag from node" )
@@ -70,11 +113,11 @@ TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
70
113
REQUIRE_NOTHROW (db.run_import (options, " n10 v3 dD\n " ));
71
114
}
72
115
73
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
116
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
74
117
}
75
118
76
119
TEMPLATE_TEST_CASE (" updating a way" , " " , options_slim_default,
77
- options_slim_expire)
120
+ options_slim_expire, options_slim_schema )
78
121
{
79
122
options_t options = TestType::options ();
80
123
@@ -86,9 +129,9 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
86
129
87
130
auto conn = db.db ().connect ();
88
131
89
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
90
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
91
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ,
132
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
133
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
134
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
92
135
" osm_id = 20 AND tags->'highway' = 'primary' "
93
136
" AND ST_NumPoints(geom) = 2" ));
94
137
@@ -97,18 +140,18 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
97
140
REQUIRE_NOTHROW (
98
141
db.run_import (options, " w20 v2 dV Thighway=secondary Nn10,n11\n " ));
99
142
100
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
101
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
102
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ,
143
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
144
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
145
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
103
146
" osm_id = 20 AND tags->'highway' = "
104
147
" 'secondary' AND ST_NumPoints(geom) = 2" ));
105
148
106
149
// now change a node in the way...
107
150
REQUIRE_NOTHROW (db.run_import (options, " n10 v2 dV x10.0 y10.3\n " ));
108
151
109
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
110
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
111
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ,
152
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
153
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
154
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
112
155
" osm_id = 20 AND tags->'highway' = "
113
156
" 'secondary' AND ST_NumPoints(geom) = 2" ));
114
157
@@ -117,21 +160,21 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
117
160
options, " n12 v1 dV x10.2 y10.1\n "
118
161
" w20 v3 dV Thighway=residential Nn10,n11,n12\n " ));
119
162
120
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
121
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
122
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ,
163
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
164
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
165
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
123
166
" osm_id = 20 AND tags->'highway' = "
124
167
" 'residential' AND ST_NumPoints(geom) = 3" ));
125
168
126
169
// now delete the way...
127
170
REQUIRE_NOTHROW (db.run_import (options, " w20 v4 dD\n " ));
128
171
129
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
130
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
172
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
173
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
131
174
}
132
175
133
176
TEMPLATE_TEST_CASE (" ways as linestrings and polygons" , " " , options_slim_default,
134
- options_slim_expire)
177
+ options_slim_expire, options_slim_schema )
135
178
{
136
179
options_t options = TestType::options ();
137
180
@@ -145,10 +188,11 @@ TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
145
188
146
189
auto conn = db.db ().connect ();
147
190
148
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
149
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
150
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ));
151
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ,
191
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
192
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
193
+ REQUIRE (1 ==
194
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
195
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , options),
152
196
" osm_id = 20 AND tags->'building' = 'yes' AND "
153
197
" ST_GeometryType(geom) = 'ST_Polygon'" ));
154
198
@@ -157,48 +201,52 @@ TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
157
201
REQUIRE_NOTHROW (db.run_import (
158
202
options, " w20 v2 dV Thighway=secondary Nn10,n11,n12,n13,n10\n " ));
159
203
160
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
161
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
204
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
205
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
162
206
REQUIRE (1 ==
163
- conn.get_count (" osm2pgsql_test_line" ,
207
+ conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
164
208
" osm_id = 20 AND tags->'highway' = 'secondary' AND "
165
209
" ST_GeometryType(geom) = 'ST_LineString'" ));
166
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
210
+ REQUIRE (0 ==
211
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
167
212
168
213
// now remove a node from the way...
169
214
REQUIRE_NOTHROW (db.run_import (
170
215
options, " w20 v3 dV Thighway=secondary Nn10,n11,n12,n13\n " ));
171
216
172
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
173
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
217
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , options) ));
218
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ));
174
219
REQUIRE (1 ==
175
- conn.get_count (" osm2pgsql_test_line" ,
220
+ conn.get_count (with_schema ( " osm2pgsql_test_line" , options) ,
176
221
" osm_id = 20 AND tags->'highway' = 'secondary' AND "
177
222
" ST_GeometryType(geom) = 'ST_LineString'" ));
178
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
223
+ REQUIRE (0 ==
224
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
179
225
180
226
// now change the tag back to an area tag (but the way is not closed)...
181
227
REQUIRE_NOTHROW (
182
228
db.run_import (options, " w20 v4 dV Tbuilding=yes Nn10,n11,n12,n13\n " ));
183
229
184
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
185
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
186
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
230
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
231
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
232
+ REQUIRE (0 ==
233
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
187
234
188
235
// now close the way again
189
236
REQUIRE_NOTHROW (db.run_import (
190
237
options, " w20 v5 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n " ));
191
238
192
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
193
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
194
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ));
195
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ,
239
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
240
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
241
+ REQUIRE (1 ==
242
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
243
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , options),
196
244
" osm_id = 20 AND tags->'building' = 'yes' AND "
197
245
" ST_GeometryType(geom) = 'ST_Polygon'" ));
198
246
}
199
247
200
248
TEMPLATE_TEST_CASE (" multipolygons" , " " , options_slim_default,
201
- options_slim_expire)
249
+ options_slim_expire, options_slim_schema )
202
250
{
203
251
options_t options = TestType::options ();
204
252
@@ -213,10 +261,11 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
213
261
214
262
auto conn = db.db ().connect ();
215
263
216
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
217
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
218
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ));
219
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ,
264
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
265
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
266
+ REQUIRE (1 ==
267
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
268
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , options),
220
269
" osm_id = -30 AND tags->'building' = 'yes' AND "
221
270
" ST_GeometryType(geom) = 'ST_Polygon'" ));
222
271
@@ -226,10 +275,11 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
226
275
options,
227
276
" r30 v2 dV Ttype=multipolygon,building=yes,name=Shed Mw20@\n " ));
228
277
229
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
230
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
231
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ));
232
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_polygon" ,
278
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
279
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
280
+ REQUIRE (1 ==
281
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
282
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , options),
233
283
" osm_id = -30 AND tags->'building' = 'yes' AND "
234
284
" ST_GeometryType(geom) = 'ST_Polygon'" ));
235
285
@@ -244,7 +294,8 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
244
294
options, " r30 v3 dV Tbuilding=yes,name=Shed Mw20@\n " ));
245
295
}
246
296
247
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
248
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
249
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
297
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , options)));
298
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , options)));
299
+ REQUIRE (0 ==
300
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , options)));
250
301
}
0 commit comments