-
Notifications
You must be signed in to change notification settings - Fork 65
Unnecessary read restriction #516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dgaubert
wants to merge
9
commits into
master
Choose a base branch
from
513-unnecessary-read-restriction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5804a44
Avoid singletons
dgaubert 2850c35
Use private method notation
dgaubert 9fd8fe2
Extract condition
dgaubert b01eb2c
Improve readability
dgaubert e4a07a4
Remove unnecessary condition
dgaubert 615e1ce
Improve readability
dgaubert 6b64eb8
Rename class
dgaubert 0bd0f85
Extract conditions
dgaubert fcf72d3
Add tests
dgaubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
require('../../helper'); | ||
|
||
const server = require('../../../app/server')(); | ||
const assert = require('../../support/assert'); | ||
const querystring = require('querystring'); | ||
|
||
describe('Read restriction on "geometry_columns"', function() { | ||
describe('OGR formats', function () { | ||
it('GET /api/v1/sql downloads KML file from a private table', function (done){ | ||
const query = querystring.stringify({ | ||
api_key: 1234, | ||
q: "SELECT * FROM private_table LIMIT 1", | ||
format: "kml", | ||
filename: 'private_table' | ||
}); | ||
assert.response(server, { | ||
url: '/api/v1/sql?' + query, | ||
headers: { host: 'vizzuality.cartodb.com' }, | ||
method: 'GET' | ||
},{ }, function(err, res){ | ||
assert.equal(res.statusCode, 200, res.body); | ||
|
||
const cd = res.headers['content-disposition']; | ||
|
||
assert.ok(/filename=private_table.kml/gi.test(cd), cd); | ||
assert.equal(res.headers['content-type'], 'application/kml; charset=utf-8'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('GET /api/v1/sql downloads a KML file from a public table', function (done){ | ||
const query = querystring.stringify({ | ||
q: "SELECT * FROM populated_places_simple_reduced LIMIT 1", | ||
format: "kml", | ||
filename: 'populated_places_simple_reduced' | ||
}); | ||
assert.response(server, { | ||
url: '/api/v1/sql?' + query, | ||
headers: { host: 'vizzuality.cartodb.com' }, | ||
method: 'GET' | ||
},{ }, function(err, res){ | ||
assert.equal(res.statusCode, 200, res.body); | ||
|
||
const cd = res.headers['content-disposition']; | ||
|
||
assert.ok(/filename=populated_places_simple_reduced.kml/gi.test(cd), cd); | ||
assert.equal(res.headers['content-type'], 'application/kml; charset=utf-8'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('GET /api/v1/sql downloads a KML file from "geometry_columns" view', function (done){ | ||
const query = querystring.stringify({ | ||
q: "SELECT * FROM geometry_columns LIMIT 1", | ||
format: "kml", | ||
filename: 'geometry_columns' | ||
}); | ||
|
||
assert.response(server, { | ||
url: '/api/v1/sql?' + query, | ||
headers: { host: 'vizzuality.cartodb.com' }, | ||
method: 'GET' | ||
},{ }, function(err, res){ | ||
assert.equal(res.statusCode, 200, res.body); | ||
|
||
const cd = res.headers['content-disposition']; | ||
|
||
assert.ok(/filename=geometry_columns.kml/gi.test(cd), cd); | ||
assert.equal(res.headers['content-type'], 'application/kml; charset=utf-8'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('GET /api/v1/sql downloads a KML file with master api_key from "geometry_columns" view', function (done){ | ||
const query = querystring.stringify({ | ||
api_key: 1234, | ||
q: "SELECT * FROM geometry_columns LIMIT 1", | ||
format: "kml", | ||
filename: 'geometry_columns' | ||
}); | ||
|
||
assert.response(server, { | ||
url: '/api/v1/sql?' + query, | ||
headers: { host: 'vizzuality.cartodb.com' }, | ||
method: 'GET' | ||
},{ }, function(err, res){ | ||
assert.equal(res.statusCode, 200, res.body); | ||
|
||
const cd = res.headers['content-disposition']; | ||
|
||
assert.ok(/filename=geometry_columns.kml/gi.test(cd), cd); | ||
assert.equal(res.headers['content-type'], 'application/kml; charset=utf-8'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @pramsey!
I've started fixing #513, but I realized that I'm not sure which is the real use case that you want to be tackled. OGR driver only works when you want to download specific formats, such as:
kml
,csv
,shp
, etc... When you try to export akml
file of a private table w/oapi_key
it fails. If you send the request w/ yourapi_key
it works. And if you want to export data from a public table you can request it with and without themaster api_key
. So far so good, no system tables are involved for public tables when you use the OGR driver.When I try to send the folowing query w/o
api_key
(see this tests ^^):SELECT * FROM geometry_columns LIMIT 1
it fails withsystem tables are forbidden
. I understand that this is the use case that raises this issue, doesn't it?If not, please help to me to understand better this issue. I've implemented a few tests with the examples that I just descibed.
Thanks in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For folks using OGR in a "not CARTO" context, the first thing OGR will do is ask CARTO, "hey, what tables are there?" (this is what happens when an OGRDataSource is instantiated). There's even a super ugly hack in OGR where it tries to sneak a peak at the system tables without letting on to CARTO that it is doing so.
So, running
EXPORT CARTO_API_KEY=dfadfa ogrinfo CARTO:pramsey
should return to e a list of tables I can read from, for example. Similarly, if I'm using an OGR driver to feed QGIS, when I pop open the layer selector I should see all the layers I have read access to.Now, as it stands we're not going to re-open access to the pg_* tables, but the geometry_columns view is already a way to get a list of layers that are visible to the current user, so that's not a bad thing to open up.
Anyways, the use case is "given this key, what can I see?" and the apps that use it are things like ogrinfo and any other "select the thing you want" style application. Otherwise you're expecting the user to arrive with an a priori list of things she has access to, which may not be the case.