| 1 |
<!-- a resource descriptor to more-or-less safely test a couple of operations |
| 2 |
--> |
| 3 |
|
| 4 |
<resource resdir="__system" schema="tests"> |
| 5 |
<service id="coredump" limitTo="gavoadmin"> |
| 6 |
<pythonCore> |
| 7 |
<coreProc> |
| 8 |
<code> |
| 9 |
import os, signal |
| 10 |
os.kill(os.getpid(), signal.SIGSEGV) |
| 11 |
</code> |
| 12 |
</coreProc> |
| 13 |
</pythonCore> |
| 14 |
</service> |
| 15 |
|
| 16 |
<fixedQueryCore id="resetcore" writable="True" |
| 17 |
query="delete from tests.files where name='c'"> |
| 18 |
<outputTable/> |
| 19 |
</fixedQueryCore> |
| 20 |
|
| 21 |
<service id="reset" core="resetcore"> |
| 22 |
<meta name="title">Reset Test Tables</meta> |
| 23 |
<meta name="shortName">testtables_reset</meta> |
| 24 |
</service> |
| 25 |
|
| 26 |
<fixedQueryCore id="timeoutcore" timeout="1" query= |
| 27 |
"select (select avg(asin(sqrt(x)/224.0)) from generate_series(1, whomp) as x) as q from generate_series(1, 50000) as whomp"> |
| 28 |
<outputTable> |
| 29 |
<column name="foo"/> |
| 30 |
</outputTable> |
| 31 |
</fixedQueryCore> |
| 32 |
|
| 33 |
<service id="timeout" core="timeoutcore"> |
| 34 |
<meta name="title">Just wait a while for a timeout</meta> |
| 35 |
</service> |
| 36 |
|
| 37 |
<service id="limited" core="timeoutcore" limitTo="notYou"> |
| 38 |
<meta name="title">Only notYou may see this.</meta> |
| 39 |
</service> |
| 40 |
|
| 41 |
<service id="dyntemplate" allowed="form,volatile,fixed,qp"> |
| 42 |
<meta name="title">Dynamic Template Test</meta> |
| 43 |
<property name="queryField">arg</property> |
| 44 |
<fixedQueryCore query="select table_name from tap_schema.tables limit 1"> |
| 45 |
<outputTable> |
| 46 |
<param name="aFloat">1.25</param> |
| 47 |
<column name="table_name" type="text"/> |
| 48 |
</outputTable> |
| 49 |
</fixedQueryCore> |
| 50 |
<template key="fixed">//tpltest.html</template> |
| 51 |
<template key="form">//tpltest.html</template> |
| 52 |
|
| 53 |
<customDF name="titleList"> |
| 54 |
return [ |
| 55 |
{"title": "on title", "other": "ing"}, |
| 56 |
{"other": "world"}] |
| 57 |
</customDF> |
| 58 |
|
| 59 |
<customRF name="authinfo"> |
| 60 |
if ctx.request.uri.endswith(b"bombout"): |
| 61 |
return open("/dev/null") # nevow can't render a file |
| 62 |
else: |
| 63 |
return "" |
| 64 |
</customRF> |
| 65 |
</service> |
| 66 |
|
| 67 |
<service id="errors" allowed="form"> |
| 68 |
<pythonCore> |
| 69 |
<inputTable> |
| 70 |
<inputKey name="what" type="text"/> |
| 71 |
</inputTable> |
| 72 |
<coreProc> |
| 73 |
<setup> |
| 74 |
<code> |
| 75 |
from gavo import svcs |
| 76 |
</code> |
| 77 |
</setup> |
| 78 |
<code> |
| 79 |
excName = inputTable.getParam("what") |
| 80 |
if excName=="DataError": |
| 81 |
raise base.DataError("test error") |
| 82 |
raise svcs.__dict__[excName]("test error", |
| 83 |
hint="This is for testing") |
| 84 |
</code> |
| 85 |
</coreProc> |
| 86 |
</pythonCore> |
| 87 |
</service> |
| 88 |
|
| 89 |
<service id="uploads" allowed="form"> |
| 90 |
<pythonCore> |
| 91 |
<inputTable> |
| 92 |
<inputKey name="up1" type="file"/> |
| 93 |
<inputKey name="up2" type="file"/> |
| 94 |
</inputTable> |
| 95 |
<coreProc> |
| 96 |
<code> |
| 97 |
up1 = inputTable.getParam("up1") |
| 98 |
up2 = inputTable.getParam("up2") |
| 99 |
|
| 100 |
return "text/plain", "%s: %s\n%s: %s\n"%( |
| 101 |
up1[0], up1[1].read().decode("utf-8"), |
| 102 |
up2[0], up2[1].read().decode("utf-8")) |
| 103 |
</code> |
| 104 |
</coreProc> |
| 105 |
</pythonCore> |
| 106 |
</service> |
| 107 |
|
| 108 |
|
| 109 |
<regSuite id="dachs"> |
| 110 |
<regTest title="Auth required for protected form."> |
| 111 |
<url>limited/form</url> |
| 112 |
<code> |
| 113 |
self.assertHTTPStatus(401) |
| 114 |
</code> |
| 115 |
</regTest> |
| 116 |
|
| 117 |
<regTest title="DB timeout yields a nice response"> |
| 118 |
<url>timeout/form</url> |
| 119 |
<code> |
| 120 |
self.assertHasStrings("Just wait a while", |
| 121 |
"Query timed out (took too") |
| 122 |
</code> |
| 123 |
</regTest> |
| 124 |
|
| 125 |
<regTest title="Admin requires login"> |
| 126 |
<url>/seffe/__system__/adql</url> |
| 127 |
<code> |
| 128 |
self.assertHTTPStatus(401) |
| 129 |
</code> |
| 130 |
</regTest> |
| 131 |
|
| 132 |
<regTest title="Uploads are processed into file items and removed |
| 133 |
from t.w context"> |
| 134 |
<url httpMethod="POST" parSet="form"> |
| 135 |
<httpUpload fileName="test.txt" name="up1" |
| 136 |
>abc, die Katze lief im Schnee.</httpUpload> |
| 137 |
<httpUpload fileName="a.out" name="up2">hurgl</httpUpload> |
| 138 |
uploads |
| 139 |
</url> |
| 140 |
<code> |
| 141 |
self.assertHasStrings( |
| 142 |
"test.txt: abc, die Katze lief im Schnee.", |
| 143 |
"a.out: hurgl",) |
| 144 |
</code> |
| 145 |
</regTest> |
| 146 |
|
| 147 |
<regTest title="Chunked uploads work"> |
| 148 |
<url httpMethod="POST" parSet="form" httpChunkSize="10"> |
| 149 |
<httpUpload fileName="test.txt" name="up1" |
| 150 |
>abc, die Katze lief im Schnee.</httpUpload> |
| 151 |
<httpUpload fileName="a.out" name="up2">hurgl</httpUpload> |
| 152 |
uploads |
| 153 |
</url> |
| 154 |
<code> |
| 155 |
self.assertHasStrings( |
| 156 |
"test.txt: abc, die Katze lief im Schnee.", |
| 157 |
"a.out: hurgl") |
| 158 |
</code> |
| 159 |
</regTest> |
| 160 |
|
| 161 |
<regTest title="No admin link to bother regular users"> |
| 162 |
<url>/__system__/adql/query/form</url> |
| 163 |
<code> |
| 164 |
self.assertLacksStrings("Admin me") |
| 165 |
</code> |
| 166 |
</regTest> |
| 167 |
|
| 168 |
<regTest title="ADQL docs appear to be in shape"> |
| 169 |
<url>/__system__/adql/query/info</url> |
| 170 |
<code><![CDATA[ |
| 171 |
self.assertHasStrings("Service Documentation", "About ADQL", |
| 172 |
'">TAP examples</a>') |
| 173 |
]]></code> |
| 174 |
</regTest> |
| 175 |
|
| 176 |
<regTest title="Vanity redirect works"> |
| 177 |
<url>/adql</url> |
| 178 |
<code> |
| 179 |
self.assertHTTPStatus(301) |
| 180 |
self.assertHasStrings('__system__/adql/query/form"', |
| 181 |
"Moved Permanently") |
| 182 |
</code> |
| 183 |
</regTest> |
| 184 |
|
| 185 |
<regTest title="Table info on non-existing table yields useful error"> |
| 186 |
<url>/tableinfo/thistable.doesnotexist</url> |
| 187 |
<code> |
| 188 |
self.assertHasStrings("table 'thistable.doesnotexist' could not be" |
| 189 |
" located in DaCHS' table listing.") |
| 190 |
</code> |
| 191 |
</regTest> |
| 192 |
|
| 193 |
<regTest title="OAI empty request gives a proper error"> |
| 194 |
<url>/oai.xml</url> |
| 195 |
<code><![CDATA[ |
| 196 |
self.assertValidatesXSD() |
| 197 |
self.assertHasStrings( |
| 198 |
'<oai:error code="badArgument">verb</oai:error>') |
| 199 |
]]></code> |
| 200 |
</regTest> |
| 201 |
|
| 202 |
<regTest title="OAI error response validates"> |
| 203 |
<url verb="do_a_hiccup">/oai.xml</url> |
| 204 |
<code> |
| 205 |
self.assertValidatesXSD() |
| 206 |
self.assertHasStrings("'do_a_hiccup' is an unsupported operation.") |
| 207 |
</code> |
| 208 |
</regTest> |
| 209 |
|
| 210 |
<regTest title="OAI Identify validates"> |
| 211 |
<url verb="Identify">/oai.xml</url> |
| 212 |
<code> |
| 213 |
self.assertHasStrings("<oai:Identify") |
| 214 |
self.assertValidatesXSD() |
| 215 |
</code> |
| 216 |
</regTest> |
| 217 |
|
| 218 |
<regTest title="Help page is sanely delivered"> |
| 219 |
<url>/static/help.shtml</url> |
| 220 |
<code> |
| 221 |
self.assertHasStrings("Service discovery", |
| 222 |
"Search forms", "VOTable", "sidebar") |
| 223 |
</code> |
| 224 |
</regTest> |
| 225 |
|
| 226 |
<regTest title="ADQL Parse errors are reported in-form"> |
| 227 |
<url parSet="form" query="foobar">/__system__/adql/query/form</url> |
| 228 |
<code> |
| 229 |
self.assertHasStrings("Service info", "Could not parse", |
| 230 |
'Expected SELECT') |
| 231 |
</code> |
| 232 |
</regTest> |
| 233 |
|
| 234 |
<regTest title="Users table is not accessible through ADQL"> |
| 235 |
<url parSet="form" query="select * from dc.users" |
| 236 |
>/__system__/adql/query/form</url> |
| 237 |
<code> |
| 238 |
self.assertHasStrings("Could not locate table", "Result link") |
| 239 |
</code> |
| 240 |
</regTest> |
| 241 |
|
| 242 |
<regTest title="TAP error message looks like it's according to standard."> |
| 243 |
<url>/__system__/tap/run/sync</url> |
| 244 |
<code><![CDATA[ |
| 245 |
self.assertHasStrings('<RESOURCE type="results">', |
| 246 |
'<INFO name="QUERY_STATUS" value="ERROR">', |
| 247 |
"Required parameter 'lang' missing.") |
| 248 |
]]></code> |
| 249 |
</regTest> |
| 250 |
|
| 251 |
<regTest title="TAP upload with forbidden postgres names works"> |
| 252 |
<!-- the stuff that makes this possible is so brittle and ugly |
| 253 |
that I really feel like I need an integration test --> |
| 254 |
<url httpMethod="POST" LANG="ADQL" |
| 255 |
UPLOAD="foo,param:VOT" |
| 256 |
QUERY="SELECT q.*, oid FROM (SELECT oid FROM foo) AS q"> |
| 257 |
<httpUpload name="VOT" fileName="tmp.vot"><![CDATA[ |
| 258 |
<VOTABLE><RESOURCE><TABLE> |
| 259 |
<FIELD name="oid" datatype="float"/> |
| 260 |
<DATA><TABLEDATA><TR><TD>1</TD></TR></TABLEDATA></DATA> |
| 261 |
</TABLE></RESOURCE></VOTABLE> |
| 262 |
]]></httpUpload>/tap/sync</url> |
| 263 |
<code> |
| 264 |
self.assertXpath("//v:FIELD[1]", {"name": "oid"}) |
| 265 |
self.assertXpath("//v:FIELD[2]", {"name": "oid_"}) |
| 266 |
</code> |
| 267 |
</regTest> |
| 268 |
|
| 269 |
</regSuite> |
| 270 |
|
| 271 |
<regSuite id="cc" title="Caching and compression" sequential="True"> |
| 272 |
<regTest title="Root page is well-formed HTML"> |
| 273 |
<url>/</url> |
| 274 |
<code> |
| 275 |
from gavo.utils import ElementTree |
| 276 |
tree = ElementTree.fromstring(self.data) |
| 277 |
self.assertEqual(tree[1].tag, |
| 278 |
'{http://www.w3.org/1999/xhtml}body') |
| 279 |
</code> |
| 280 |
</regTest> |
| 281 |
|
| 282 |
<regTest title="Transparent compression of static resource works"> |
| 283 |
<url> |
| 284 |
<value key="Accept-Encoding">gzip</value>/</url> |
| 285 |
<code> |
| 286 |
import gzip, io |
| 287 |
stuff = gzip.GzipFile(fileobj=io.BytesIO(self.data)).read() |
| 288 |
self.assertTrue(b'src="/static/img/logo_medium.png"' in stuff, |
| 289 |
"decompressed response looks about right") |
| 290 |
for key, value in self.headers: |
| 291 |
if key=="X-Cache-Creation": |
| 292 |
self.assertFalse(value is None) |
| 293 |
break |
| 294 |
else: |
| 295 |
raise AssertionError("Compressed data comes from Cache") |
| 296 |
</code> |
| 297 |
</regTest> |
| 298 |
|
| 299 |
<regTest title="Uncompressed root page served from cache"> |
| 300 |
<url>/</url> |
| 301 |
<code> |
| 302 |
self.assertHasStrings('src="/static/img/logo_medium.png"') |
| 303 |
for key, value in self.headers: |
| 304 |
if key=="X-Cache-Creation": |
| 305 |
self.assertFalse(value is None) |
| 306 |
break |
| 307 |
else: |
| 308 |
raise AssertionError("No x-cache-creation header") |
| 309 |
</code> |
| 310 |
</regTest> |
| 311 |
|
| 312 |
<regTest title="Nevow render error yields somewhat usable document"> |
| 313 |
<url>dyntemplate/qp/bombout</url> |
| 314 |
<code> |
| 315 |
self.assertHTTPStatus(200) # I'd like this to be a 500, but |
| 316 |
# this error only happens when the status line has been |
| 317 |
# written; HTML streaming is important enough for me with |
| 318 |
# my potentially large HTML tables that I'll suck this up. |
| 319 |
# The 500 will at least be in the log. |
| 320 |
self.assertHasStrings("Internal Error", |
| 321 |
"A(n) FlattenerError exception occurred", |
| 322 |
"UnsupportedType: &lt;_io.TextIOWrapper") |
| 323 |
</code> |
| 324 |
</regTest> |
| 325 |
</regSuite> |
| 326 |
|
| 327 |
<regSuite title="error documents"> |
| 328 |
<LOOP> |
| 329 |
<csvItems> |
| 330 |
excName, expStatus, id, extraText |
| 331 |
UnknownURI, 404, cur-a, within the data center |
| 332 |
ForbiddenURI, 403, cur-b, complain fiercely |
| 333 |
WebRedirect, 301, cur-c, different URL |
| 334 |
SeeOther, 303, cur-d, Please turn |
| 335 |
Authenticate, 401, cur-e, access is protected |
| 336 |
BadMethod, 405, cur-f, HTTP method |
| 337 |
DataError, 406, cur-g, server cannot generate |
| 338 |
test error, 500, cur-h, KeyError |
| 339 |
</csvItems> |
| 340 |
<events> |
| 341 |
<regTest title="\excName renders" id="\id"> |
| 342 |
<url parSet="form" what="\excName">errors</url> |
| 343 |
<code> |
| 344 |
self.assertHasStrings('href="mailto:') |
| 345 |
self.assertHTTPStatus(\expStatus) |
| 346 |
if "\excName"=="Authenticate": |
| 347 |
# Auth template doesn't show exception |
| 348 |
self.assertHasStrings("\extraText") |
| 349 |
else: |
| 350 |
self.assertHasStrings("test error", "\extraText") |
| 351 |
</code> |
| 352 |
</regTest> |
| 353 |
</events> |
| 354 |
</LOOP> |
| 355 |
</regSuite> |
| 356 |
|
| 357 |
</resource> |