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,51 @@ 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;
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" );
72
+ }
73
+ };
74
+
75
+ // Return a string with the schema name prepended to the table name.
76
+ std::string with_schema (char const *name, options_t const *options)
77
+ {
78
+ if (options->dbschema .empty ()) {
79
+ return std::string (name);
80
+ }
81
+ log_info (options->dbschema .c_str ());
82
+ return options->dbschema + " ." + name;
83
+ }
84
+
41
85
TEMPLATE_TEST_CASE (" updating a node" , " " , options_slim_default,
42
- options_slim_expire)
86
+ options_slim_expire, options_slim_schema )
43
87
{
44
88
options_t options = TestType::options ();
45
89
@@ -48,16 +92,16 @@ TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
48
92
49
93
auto conn = db.db ().connect ();
50
94
51
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
95
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
52
96
53
97
// give the node a tag...
54
98
options.append = true ;
55
99
REQUIRE_NOTHROW (
56
100
db.run_import (options, " n10 v2 dV x10 y10 Tamenity=restaurant\n " ));
57
101
58
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_point" ));
102
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
59
103
REQUIRE (1 ==
60
- conn.get_count (" osm2pgsql_test_point" ,
104
+ conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ,
61
105
" node_id = 10 AND tags->'amenity' = 'restaurant'" ));
62
106
63
107
SECTION (" remove the tag from node" )
@@ -70,11 +114,11 @@ TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
70
114
REQUIRE_NOTHROW (db.run_import (options, " n10 v3 dD\n " ));
71
115
}
72
116
73
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
117
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
74
118
}
75
119
76
120
TEMPLATE_TEST_CASE (" updating a way" , " " , options_slim_default,
77
- options_slim_expire)
121
+ options_slim_expire, options_slim_schema )
78
122
{
79
123
options_t options = TestType::options ();
80
124
@@ -86,9 +130,9 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
86
130
87
131
auto conn = db.db ().connect ();
88
132
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" ,
133
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
134
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
135
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
92
136
" osm_id = 20 AND tags->'highway' = 'primary' "
93
137
" AND ST_NumPoints(geom) = 2" ));
94
138
@@ -97,18 +141,18 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
97
141
REQUIRE_NOTHROW (
98
142
db.run_import (options, " w20 v2 dV Thighway=secondary Nn10,n11\n " ));
99
143
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" ,
144
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
145
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
146
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
103
147
" osm_id = 20 AND tags->'highway' = "
104
148
" 'secondary' AND ST_NumPoints(geom) = 2" ));
105
149
106
150
// now change a node in the way...
107
151
REQUIRE_NOTHROW (db.run_import (options, " n10 v2 dV x10.0 y10.3\n " ));
108
152
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" ,
153
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
154
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
155
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
112
156
" osm_id = 20 AND tags->'highway' = "
113
157
" 'secondary' AND ST_NumPoints(geom) = 2" ));
114
158
@@ -117,21 +161,21 @@ TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
117
161
options, " n12 v1 dV x10.2 y10.1\n "
118
162
" w20 v3 dV Thighway=residential Nn10,n11,n12\n " ));
119
163
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" ,
164
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
165
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
166
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
123
167
" osm_id = 20 AND tags->'highway' = "
124
168
" 'residential' AND ST_NumPoints(geom) = 3" ));
125
169
126
170
// now delete the way...
127
171
REQUIRE_NOTHROW (db.run_import (options, " w20 v4 dD\n " ));
128
172
129
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
130
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_line" ));
173
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
174
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
131
175
}
132
176
133
177
TEMPLATE_TEST_CASE (" ways as linestrings and polygons" , " " , options_slim_default,
134
- options_slim_expire)
178
+ options_slim_expire, options_slim_schema )
135
179
{
136
180
options_t options = TestType::options ();
137
181
@@ -145,10 +189,11 @@ TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
145
189
146
190
auto conn = db.db ().connect ();
147
191
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" ,
192
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
193
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
194
+ REQUIRE (1 ==
195
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
196
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options),
152
197
" osm_id = 20 AND tags->'building' = 'yes' AND "
153
198
" ST_GeometryType(geom) = 'ST_Polygon'" ));
154
199
@@ -157,48 +202,52 @@ TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
157
202
REQUIRE_NOTHROW (db.run_import (
158
203
options, " w20 v2 dV Thighway=secondary Nn10,n11,n12,n13,n10\n " ));
159
204
160
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
161
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
205
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
206
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
162
207
REQUIRE (1 ==
163
- conn.get_count (" osm2pgsql_test_line" ,
208
+ conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
164
209
" osm_id = 20 AND tags->'highway' = 'secondary' AND "
165
210
" ST_GeometryType(geom) = 'ST_LineString'" ));
166
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
211
+ REQUIRE (0 ==
212
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
167
213
168
214
// now remove a node from the way...
169
215
REQUIRE_NOTHROW (db.run_import (
170
216
options, " w20 v3 dV Thighway=secondary Nn10,n11,n12,n13\n " ));
171
217
172
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_point" ));
173
- REQUIRE (1 == conn.get_count (" osm2pgsql_test_line" ));
218
+ REQUIRE (0 == conn.get_count (with_schema ( " osm2pgsql_test_point" , &options) ));
219
+ REQUIRE (1 == conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ));
174
220
REQUIRE (1 ==
175
- conn.get_count (" osm2pgsql_test_line" ,
221
+ conn.get_count (with_schema ( " osm2pgsql_test_line" , &options) ,
176
222
" osm_id = 20 AND tags->'highway' = 'secondary' AND "
177
223
" ST_GeometryType(geom) = 'ST_LineString'" ));
178
- REQUIRE (0 == conn.get_count (" osm2pgsql_test_polygon" ));
224
+ REQUIRE (0 ==
225
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
179
226
180
227
// now change the tag back to an area tag (but the way is not closed)...
181
228
REQUIRE_NOTHROW (
182
229
db.run_import (options, " w20 v4 dV Tbuilding=yes Nn10,n11,n12,n13\n " ));
183
230
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" ));
231
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
232
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
233
+ REQUIRE (0 ==
234
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
187
235
188
236
// now close the way again
189
237
REQUIRE_NOTHROW (db.run_import (
190
238
options, " w20 v5 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n " ));
191
239
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" ,
240
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
241
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
242
+ REQUIRE (1 ==
243
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
244
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options),
196
245
" osm_id = 20 AND tags->'building' = 'yes' AND "
197
246
" ST_GeometryType(geom) = 'ST_Polygon'" ));
198
247
}
199
248
200
249
TEMPLATE_TEST_CASE (" multipolygons" , " " , options_slim_default,
201
- options_slim_expire)
250
+ options_slim_expire, options_slim_schema )
202
251
{
203
252
options_t options = TestType::options ();
204
253
@@ -213,10 +262,11 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
213
262
214
263
auto conn = db.db ().connect ();
215
264
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" ,
265
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
266
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
267
+ REQUIRE (1 ==
268
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
269
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options),
220
270
" osm_id = -30 AND tags->'building' = 'yes' AND "
221
271
" ST_GeometryType(geom) = 'ST_Polygon'" ));
222
272
@@ -226,10 +276,11 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
226
276
options,
227
277
" r30 v2 dV Ttype=multipolygon,building=yes,name=Shed Mw20@\n " ));
228
278
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" ,
279
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
280
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
281
+ REQUIRE (1 ==
282
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
283
+ REQUIRE (1 == conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options),
233
284
" osm_id = -30 AND tags->'building' = 'yes' AND "
234
285
" ST_GeometryType(geom) = 'ST_Polygon'" ));
235
286
@@ -244,7 +295,8 @@ TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
244
295
options, " r30 v3 dV Tbuilding=yes,name=Shed Mw20@\n " ));
245
296
}
246
297
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" ));
298
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_point" , &options)));
299
+ REQUIRE (0 == conn.get_count (with_schema (" osm2pgsql_test_line" , &options)));
300
+ REQUIRE (0 ==
301
+ conn.get_count (with_schema (" osm2pgsql_test_polygon" , &options)));
250
302
}
0 commit comments