@@ -37,17 +37,17 @@ describe('app.test', function () {
37
37
method : 'GET'
38
38
} , { } , function ( err , res ) {
39
39
assert . ifError ( err ) ;
40
- assert . strictEqual ( res . statusCode , 200 , res . body ) ;
40
+ assert . strictEqual ( res . statusCode , 401 , res . body ) ;
41
41
// Check cache headers
42
- assert . strictEqual ( res . headers [ 'x-cache-channel' ] , 'cartodb_test_user_1_db:public.untitle_table_4' ) ;
43
- assert . strictEqual ( res . headers [ 'cache-control' ] , expectedCacheControl ) ;
42
+ assert . strictEqual ( res . headers [ 'x-cache-channel' ] , undefined ) ;
43
+ assert . strictEqual ( res . headers [ 'cache-control' ] , undefined ) ;
44
44
done ( ) ;
45
45
} ) ;
46
46
} ) ;
47
47
48
48
it ( 'GET /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers' , function ( done ) {
49
49
assert . response ( server , {
50
- url : '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4' ,
50
+ url : '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4&api_key=1234 ' ,
51
51
headers : { host : 'vizzuality.cartodb.com' } ,
52
52
method : 'GET'
53
53
} , { } , function ( err , res ) {
@@ -63,7 +63,7 @@ describe('app.test', function () {
63
63
method : 'GET'
64
64
} , { } , function ( err , res ) {
65
65
assert . ifError ( err ) ;
66
- assert . strictEqual ( res . statusCode , 200 , res . body ) ;
66
+ assert . strictEqual ( res . statusCode , 401 , res . body ) ;
67
67
done ( ) ;
68
68
} ) ;
69
69
} ) ;
@@ -91,7 +91,7 @@ describe('app.test', function () {
91
91
method : 'POST'
92
92
} , { } , function ( err , res ) {
93
93
assert . ifError ( err ) ;
94
- assert . strictEqual ( res . statusCode , 200 , res . body ) ;
94
+ assert . strictEqual ( res . statusCode , 401 , res . body ) ;
95
95
done ( ) ;
96
96
} ) ;
97
97
} ) ;
@@ -105,10 +105,10 @@ describe('app.test', function () {
105
105
} , {
106
106
} , function ( err , res ) {
107
107
assert . ifError ( err ) ;
108
- assert . strictEqual ( res . statusCode , 403 , res . statusCode + ': ' + res . body ) ;
108
+ assert . strictEqual ( res . statusCode , 401 , res . statusCode + ': ' + res . body ) ;
109
109
assert . deepStrictEqual ( res . headers [ 'content-type' ] , 'application/json; charset=utf-8' ) ;
110
110
assert . deepStrictEqual ( res . headers [ 'content-disposition' ] , 'inline' ) ;
111
- assert . ok ( JSON . parse ( res . body ) . error [ 0 ] . match ( / p e r m i s s i o n d e n i e d f o r . + ? u n t i t l e _ t a b l e _ 4 / ) ) ;
111
+ assert . deepStrictEqual ( JSON . parse ( res . body ) . error [ 0 ] , 'unauthorized' ) ;
112
112
done ( ) ;
113
113
} ) ;
114
114
} ) ;
@@ -121,10 +121,10 @@ describe('app.test', function () {
121
121
} , {
122
122
} , function ( err , res ) {
123
123
assert . ifError ( err ) ;
124
- assert . strictEqual ( res . statusCode , 400 , res . statusCode + ': ' + res . body ) ;
124
+ assert . strictEqual ( res . statusCode , 401 , res . statusCode + ': ' + res . body ) ;
125
125
assert . deepStrictEqual ( res . headers [ 'content-type' ] , 'application/json; charset=utf-8' ) ;
126
126
assert . deepStrictEqual ( res . headers [ 'content-disposition' ] , 'inline' ) ;
127
- assert . ok ( JSON . parse ( res . body ) . error [ 0 ] . match ( / m u s t b e o w n e r o f . + ? u n t i t l e _ t a b l e _ 4 / ) ) ;
127
+ assert . deepStrictEqual ( JSON . parse ( res . body ) . error [ 0 ] , 'unauthorized' ) ;
128
128
done ( ) ;
129
129
} ) ;
130
130
} ) ;
@@ -135,7 +135,7 @@ describe('app.test', function () {
135
135
headers : { host : 'vizzuality.cartodb.com' } ,
136
136
method : 'GET'
137
137
} , {
138
- status : 400
138
+ status : 401
139
139
} , done ) ;
140
140
} ) ;
141
141
@@ -146,10 +146,10 @@ describe('app.test', function () {
146
146
method : 'GET'
147
147
} , { } , function ( err , res ) {
148
148
assert . ifError ( err ) ;
149
- assert . strictEqual ( res . statusCode , 400 , res . statusCode + ': ' + res . body ) ;
149
+ assert . strictEqual ( res . statusCode , 401 , res . statusCode + ': ' + res . body ) ;
150
150
assert . deepStrictEqual ( res . headers [ 'content-type' ] , 'application/json; charset=utf-8' ) ;
151
151
assert . deepStrictEqual ( res . headers [ 'content-disposition' ] , 'inline' ) ;
152
- assert . ok ( JSON . parse ( res . body ) . error [ 0 ] . match ( / m u s t b e o w n e r o f . + ? u n t i t l e _ t a b l e _ 4 / ) ) ;
152
+ assert . deepStrictEqual ( JSON . parse ( res . body ) . error [ 0 ] , 'unauthorized' ) ;
153
153
done ( ) ;
154
154
} ) ;
155
155
} ) ;
@@ -352,7 +352,11 @@ describe('app.test', function () {
352
352
353
353
it ( 'sends a 400 when an unsupported format is requested' , function ( done ) {
354
354
assert . response ( server , {
355
- url : '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4&format=unknown' ,
355
+ url : '/api/v1/sql?' + querystring . stringify ( {
356
+ q : 'SELECT * FROM untitle_table_4' ,
357
+ api_key : 1234 ,
358
+ format : 'unknown'
359
+ } ) ,
356
360
headers : { host : 'vizzuality.cartodb.com' } ,
357
361
method : 'GET'
358
362
} , { } , function ( err , res ) {
@@ -367,7 +371,10 @@ describe('app.test', function () {
367
371
368
372
it ( 'GET /api/v1/sql with SQL parameter and no format, ensuring content-disposition set to json' , function ( done ) {
369
373
assert . response ( server , {
370
- url : '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4' ,
374
+ url : '/api/v1/sql?' + querystring . stringify ( {
375
+ q : 'SELECT * FROM untitle_table_4' ,
376
+ api_key : 1234
377
+ } ) ,
371
378
headers : { host : 'vizzuality.cartodb.com' } ,
372
379
method : 'GET'
373
380
} , { } , function ( err , res ) {
@@ -385,7 +392,7 @@ describe('app.test', function () {
385
392
it ( 'POST /api/v1/sql with SQL parameter and no format, ensuring content-disposition set to json' , function ( done ) {
386
393
assert . response ( server , {
387
394
url : '/api/v1/sql' ,
388
- data : querystring . stringify ( { q : 'SELECT * FROM untitle_table_4' } ) ,
395
+ data : querystring . stringify ( { q : 'SELECT * FROM untitle_table_4' , api_key : 1234 } ) ,
389
396
headers : { host : 'vizzuality.cartodb.com' , 'Content-Type' : 'application/x-www-form-urlencoded' } ,
390
397
method : 'POST'
391
398
} , { } , function ( err , res ) {
@@ -402,7 +409,11 @@ describe('app.test', function () {
402
409
403
410
it ( 'GET /api/v1/sql with SQL parameter and no format, but a filename' , function ( done ) {
404
411
assert . response ( server , {
405
- url : '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4&filename=x' ,
412
+ url : '/api/v1/sql?' + querystring . stringify ( {
413
+ q : 'SELECT * FROM untitle_table_4' ,
414
+ api_key : 1234 ,
415
+ filename : 'x'
416
+ } ) ,
406
417
headers : { host : 'vizzuality.cartodb.com' } ,
407
418
method : 'GET'
408
419
} , { } , function ( err , res ) {
@@ -419,7 +430,10 @@ describe('app.test', function () {
419
430
420
431
it ( 'GET /api/v1/sql ensure cross domain set on errors' , function ( done ) {
421
432
assert . response ( server , {
422
- url : '/api/v1/sql?q=SELECT%20*gadfgadfg%20FROM%20untitle_table_4' ,
433
+ url : '/api/v1/sql?' + querystring . stringify ( {
434
+ q : 'SELECT gadfgadfg FROM untitle_table_4' ,
435
+ api_key : 1234
436
+ } ) ,
423
437
headers : { host : 'vizzuality.cartodb.com' } ,
424
438
method : 'GET'
425
439
} , {
@@ -457,8 +471,8 @@ describe('app.test', function () {
457
471
it ( 'GET decent error if SQL is broken' , function ( done ) {
458
472
assert . response ( server , {
459
473
url : '/api/v1/sql?' + querystring . stringify ( {
460
- q :
461
- 'SELECT star FROM this and that'
474
+ q : 'SELECT star FROM this and that' ,
475
+ api_key : 1234
462
476
} ) ,
463
477
headers : { host : 'vizzuality.cartodb.com' } ,
464
478
method : 'GET'
@@ -478,8 +492,8 @@ describe('app.test', function () {
478
492
it ( 'numeric arrays are rendered as such' , function ( done ) {
479
493
assert . response ( server , {
480
494
url : '/api/v1/sql?' + querystring . stringify ( {
481
- q :
482
- 'SELECT ARRAY[8.7,4.3]::numeric[] as x'
495
+ q : 'SELECT ARRAY[8.7,4.3]::numeric[] as x' ,
496
+ api_key : 1234
483
497
} ) ,
484
498
headers : { host : 'vizzuality.localhost.lan:8080' } ,
485
499
method : 'GET'
@@ -510,7 +524,8 @@ describe('app.test', function () {
510
524
// See https://github.com/CartoDB/CartoDB-SQL-API/issues/117
511
525
', now()::date as i' +
512
526
", '1'::numeric as j" +
513
- ' LIMIT 0'
527
+ ' LIMIT 0' ,
528
+ api_key : 1234
514
529
} ) ,
515
530
headers : { host : 'vizzuality.cartodb.com' } ,
516
531
method : 'GET'
@@ -547,7 +562,8 @@ describe('app.test', function () {
547
562
' ARRAY[d] AS _d, ' +
548
563
' ARRAY[e] AS _e, ' +
549
564
' ARRAY[f] AS _f ' +
550
- 'FROM inp'
565
+ 'FROM inp' ,
566
+ api_key : 1234
551
567
} ) ,
552
568
headers : { host : 'vizzuality.cartodb.com' } ,
553
569
method : 'GET'
@@ -589,7 +605,8 @@ describe('app.test', function () {
589
605
var next = this ;
590
606
assert . response ( server , {
591
607
url : '/api/v1/sql?' + querystring . stringify ( {
592
- q : "SET timezone TO 'Europe/Rome'; SELECT '2000-01-01T00:00:00+01'::timestamptz as d"
608
+ q : "SET timezone TO 'Europe/Rome'; SELECT '2000-01-01T00:00:00+01'::timestamptz as d" ,
609
+ api_key : 1234
593
610
} ) ,
594
611
headers : { host : 'vizzuality.cartodb.com' } ,
595
612
method : 'GET'
@@ -610,7 +627,8 @@ describe('app.test', function () {
610
627
var next = this ;
611
628
assert . response ( server , {
612
629
url : '/api/v1/sql?' + querystring . stringify ( {
613
- q : "SET timezone TO 'Europe/Rome'; SELECT '2000-01-01T00:00:00'::timestamp as d"
630
+ q : "SET timezone TO 'Europe/Rome'; SELECT '2000-01-01T00:00:00'::timestamp as d" ,
631
+ api_key : 1234
614
632
} ) ,
615
633
headers : { host : 'vizzuality.cartodb.com' } ,
616
634
method : 'GET'
@@ -631,7 +649,8 @@ describe('app.test', function () {
631
649
var next = this ;
632
650
assert . response ( server , {
633
651
url : '/api/v1/sql?' + querystring . stringify ( {
634
- q : "SET timezone TO 'UTC'; SELECT '2000-01-01T00:00:00+00'::timestamptz as d"
652
+ q : "SET timezone TO 'UTC'; SELECT '2000-01-01T00:00:00+00'::timestamptz as d" ,
653
+ api_key : 1234
635
654
} ) ,
636
655
headers : { host : 'vizzuality.cartodb.com' } ,
637
656
method : 'GET'
@@ -652,7 +671,8 @@ describe('app.test', function () {
652
671
var next = this ;
653
672
assert . response ( server , {
654
673
url : '/api/v1/sql?' + querystring . stringify ( {
655
- q : "SET timezone TO 'UTC'; SELECT '2000-01-01T00:00:00'::timestamp as d"
674
+ q : "SET timezone TO 'UTC'; SELECT '2000-01-01T00:00:00'::timestamp as d" ,
675
+ api_key : 1234
656
676
} ) ,
657
677
headers : { host : 'vizzuality.cartodb.com' } ,
658
678
method : 'GET'
@@ -695,7 +715,8 @@ describe('app.test', function () {
695
715
var next = this ;
696
716
assert . response ( server , {
697
717
url : '/api/v1/sql?' + querystring . stringify ( {
698
- q : "SET client_min_messages TO 'notice'; select raise('notice', 'hello notice')"
718
+ q : "SET client_min_messages TO 'notice'; select raise('notice', 'hello notice')" ,
719
+ api_key : 1234
699
720
} ) ,
700
721
headers : { host : 'vizzuality.cartodb.com' } ,
701
722
method : 'GET'
@@ -716,7 +737,8 @@ describe('app.test', function () {
716
737
var next = this ;
717
738
assert . response ( server , {
718
739
url : '/api/v1/sql?' + querystring . stringify ( {
719
- q : "SET client_min_messages TO 'notice'; select raise('warning', 'hello warning')"
740
+ q : "SET client_min_messages TO 'notice'; select raise('warning', 'hello warning')" ,
741
+ api_key : 1234
720
742
} ) ,
721
743
headers : { host : 'vizzuality.cartodb.com' } ,
722
744
method : 'GET'
@@ -738,7 +760,8 @@ describe('app.test', function () {
738
760
assert . response ( server , {
739
761
url : '/api/v1/sql?' + querystring . stringify ( {
740
762
q : "SET client_min_messages TO 'notice'; select raise('warning', 'hello again warning'), " +
741
- "raise('notice', 'hello again notice');"
763
+ "raise('notice', 'hello again notice');" ,
764
+ api_key : 1234
742
765
} ) ,
743
766
headers : { host : 'vizzuality.cartodb.com' } ,
744
767
method : 'GET'
@@ -793,7 +816,11 @@ describe('app.test', function () {
793
816
794
817
it ( 'GET with callback must return 200 status error even if it is an error' , function ( done ) {
795
818
assert . response ( server , {
796
- url : '/api/v1/sql?q=DROP%20TABLE%20untitle_table_4&callback=foo_jsonp' ,
819
+ url : '/api/v1/sql?' + querystring . stringify ( {
820
+ q : 'DROP TABLE untitle_table_4' ,
821
+ api_key : 1234 ,
822
+ callback : 'foo_jsonp'
823
+ } ) ,
797
824
headers : { host : 'vizzuality.cartodb.com' } ,
798
825
method : 'GET'
799
826
} , { } , function ( err , res ) {
@@ -814,7 +841,10 @@ describe('app.test', function () {
814
841
815
842
it ( 'GET with slow query exceeding statement timeout returns proper error message' , function ( done ) {
816
843
assert . response ( server , {
817
- url : '/api/v1/sql?q=select%20pg_sleep(2.1)%20as%20sleep' ,
844
+ url : '/api/v1/sql?' + querystring . stringify ( {
845
+ q : 'select pg_sleep(2.1) as sleep' ,
846
+ api_key : 1234
847
+ } ) ,
818
848
headers : { host : 'vizzuality.cartodb.com' } ,
819
849
method : 'GET'
820
850
} ,
@@ -838,7 +868,7 @@ describe('app.test', function () {
838
868
839
869
it ( 'GET with slow query exceeding statement timeout returns proper error message (streaming)' , function ( done ) {
840
870
assert . response ( server , {
841
- url : '/api/v1/sql?q=SELECT%20pg_sleep(generate_series(2,10)/10.0)' ,
871
+ url : '/api/v1/sql?q=SELECT%20pg_sleep(generate_series(2,10)/10.0)&api_key=1234 ' ,
842
872
headers : { host : 'vizzuality.cartodb.com' } ,
843
873
method : 'GET'
844
874
} ,
@@ -875,7 +905,8 @@ describe('app.test', function () {
875
905
server ,
876
906
{
877
907
url : '/api/v1/sql?' + querystring . stringify ( {
878
- q : 'SELECT * FROM untitle_table_4'
908
+ q : 'SELECT * FROM untitle_table_4' ,
909
+ api_key : 1234
879
910
} ) ,
880
911
headers : {
881
912
host : 'vizzuality.cartodb.com'
0 commit comments