mirror of
https://github.com/xbgmsharp/postgsail.git
synced 2025-09-17 11:17:46 +00:00
Update tests to match the new anonymous access feature
This commit is contained in:
@@ -28,31 +28,31 @@ var moment = require("moment");
|
|||||||
name: "PostgSail unit test kapla",
|
name: "PostgSail unit test kapla",
|
||||||
logs: {
|
logs: {
|
||||||
url: "/logs_view",
|
url: "/logs_view",
|
||||||
header: { name: "x-is-public", value: btoa("1,public_logs_list") },
|
header: { name: "x-is-public", value: btoa("kapla,public_logs_list,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
log: {
|
log: {
|
||||||
url: "/log_view?id=eq.1",
|
url: "/log_view?id=eq.1",
|
||||||
header: { name: "x-is-public", value: btoa("2,public_logs") },
|
header: { name: "x-is-public", value: btoa("kapla,public_logs,1") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
monitoring: {
|
monitoring: {
|
||||||
url: "/monitoring_view",
|
url: "/monitoring_view",
|
||||||
header: { name: "x-is-public", value: btoa("1,public_monitoring") },
|
header: { name: "x-is-public", value: btoa("kapla,public_monitoring,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
timelapse: {
|
timelapse: {
|
||||||
url: "/rpc/timelapse_fn",
|
url: "/rpc/timelapse_fn",
|
||||||
header: { name: "x-is-public", value: btoa("1,public_timelapse") },
|
header: { name: "x-is-public", value: btoa("kapla,public_timelapse,1") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
export_gpx: {
|
export_gpx: {
|
||||||
url: "/rpc/export_logbook_gpx_fn",
|
url: "/rpc/export_logbook_gpx_fn",
|
||||||
header: { name: "x-is-public", value: btoa("1,public_logs") },
|
header: { name: "x-is-public", value: btoa("kapla,public_logs,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
@@ -62,31 +62,31 @@ var moment = require("moment");
|
|||||||
name: "PostgSail unit test, aava",
|
name: "PostgSail unit test, aava",
|
||||||
logs: {
|
logs: {
|
||||||
url: "/logs_view",
|
url: "/logs_view",
|
||||||
header: { name: "x-is-public", value: btoa("2,public_logs_list") },
|
header: { name: "x-is-public", value: btoa("aava,public_logs_list,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
log: {
|
log: {
|
||||||
url: "/log_view?id=eq.1",
|
url: "/log_view?id=eq.3",
|
||||||
header: { name: "x-is-public", value: btoa("3,public_logs") },
|
header: { name: "x-is-public", value: btoa("aava,public_logs,3") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
monitoring: {
|
monitoring: {
|
||||||
url: "/monitoring_view",
|
url: "/monitoring_view",
|
||||||
header: { name: "x-is-public", value: btoa("2,public_monitoring") },
|
header: { name: "x-is-public", value: btoa("aava,public_monitoring,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
timelapse: {
|
timelapse: {
|
||||||
url: "/rpc/timelapse_fn",
|
url: "/rpc/timelapse_fn",
|
||||||
header: { name: "x-is-public", value: btoa("2,public_timelapse") },
|
header: { name: "x-is-public", value: btoa("aava,public_timelapse,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
export_gpx: {
|
export_gpx: {
|
||||||
url: "/rpc/export_logbook_gpx_fn",
|
url: "/rpc/export_logbook_gpx_fn",
|
||||||
header: { name: "x-is-public", value: btoa("2,public_logs") },
|
header: { name: "x-is-public", value: btoa("aava,public_logs,0") },
|
||||||
payload: null,
|
payload: null,
|
||||||
res: {},
|
res: {},
|
||||||
},
|
},
|
||||||
@@ -106,7 +106,7 @@ var moment = require("moment");
|
|||||||
.set(test.logs.header.name, test.logs.header.value)
|
.set(test.logs.header.name, test.logs.header.value)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
res.status.should.equal(401);
|
res.status.should.equal(404);
|
||||||
should.exist(res.header["content-type"]);
|
should.exist(res.header["content-type"]);
|
||||||
should.exist(res.header["server"]);
|
should.exist(res.header["server"]);
|
||||||
res.header["content-type"].should.match(new RegExp("json", "g"));
|
res.header["content-type"].should.match(new RegExp("json", "g"));
|
||||||
@@ -156,7 +156,7 @@ var moment = require("moment");
|
|||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
console.log(res.text);
|
console.log(res.text);
|
||||||
res.status.should.equal(401);
|
res.status.should.equal(404);
|
||||||
should.exist(res.header["content-type"]);
|
should.exist(res.header["content-type"]);
|
||||||
should.exist(res.header["server"]);
|
should.exist(res.header["server"]);
|
||||||
res.header["content-type"].should.match(new RegExp("json", "g"));
|
res.header["content-type"].should.match(new RegExp("json", "g"));
|
||||||
|
20
tests/sql/anonymous.sql
Normal file
20
tests/sql/anonymous.sql
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---------------------------------------------------------------------------
|
||||||
|
-- Listing
|
||||||
|
--
|
||||||
|
|
||||||
|
-- List current database
|
||||||
|
select current_database();
|
||||||
|
|
||||||
|
-- connect to the DB
|
||||||
|
\c signalk
|
||||||
|
|
||||||
|
-- output display format
|
||||||
|
\x on
|
||||||
|
|
||||||
|
\echo 'Validate anonymous access'
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_test');
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_logs_list');
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_logs', 1);
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_logs', 3);
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_monitoring');
|
||||||
|
SELECT api.ispublic_fn('kapla', 'public_timelapse');
|
23
tests/sql/anonymous.sql.output
Normal file
23
tests/sql/anonymous.sql.output
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
current_database
|
||||||
|
------------------
|
||||||
|
signalk
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
You are now connected to database "signalk" as user "username".
|
||||||
|
Expanded display is on.
|
||||||
|
Validate anonymous access
|
||||||
|
-[ RECORD 1 ]--
|
||||||
|
ispublic_fn | f
|
||||||
|
|
||||||
|
-[ RECORD 1 ]--
|
||||||
|
ispublic_fn | f
|
||||||
|
|
||||||
|
-[ RECORD 1 ]--
|
||||||
|
ispublic_fn | t
|
||||||
|
|
||||||
|
-[ RECORD 1 ]--
|
||||||
|
ispublic_fn | t
|
||||||
|
|
||||||
|
-[ RECORD 1 ]--
|
||||||
|
ispublic_fn | f
|
||||||
|
|
@@ -23,7 +23,7 @@ SELECT current_user, current_setting('user.email', true), current_setting('vesse
|
|||||||
SELECT v.name,m.client_id FROM auth.accounts a JOIN auth.vessels v ON a.role = 'user_role' AND v.owner_email = a.email JOIN api.metadata m ON m.vessel_id = v.vessel_id;
|
SELECT v.name,m.client_id FROM auth.accounts a JOIN auth.vessels v ON a.role = 'user_role' AND v.owner_email = a.email JOIN api.metadata m ON m.vessel_id = v.vessel_id;
|
||||||
|
|
||||||
\echo 'auth.accounts details'
|
\echo 'auth.accounts details'
|
||||||
SELECT a.public_id IS NOT NULL AS public_id, a.user_id IS NOT NULL AS user_id, a.email, a.first, a.last, a.pass IS NOT NULL AS pass, a.role, a.preferences->'telegram'->'chat' AS telegram, a.preferences->'pushover_user_key' AS pushover_user_key FROM auth.accounts AS a;
|
SELECT a.user_id IS NOT NULL AS user_id, a.email, a.first, a.last, a.pass IS NOT NULL AS pass, a.role, a.preferences->'telegram'->'chat' AS telegram, a.preferences->'pushover_user_key' AS pushover_user_key FROM auth.accounts AS a;
|
||||||
\echo 'auth.vessels details'
|
\echo 'auth.vessels details'
|
||||||
--SELECT 'SELECT ' || STRING_AGG('v.' || column_name, ', ') || ' FROM auth.vessels AS v' FROM information_schema.columns WHERE table_name = 'vessels' AND table_schema = 'auth' AND column_name NOT IN ('created_at', 'updated_at');
|
--SELECT 'SELECT ' || STRING_AGG('v.' || column_name, ', ') || ' FROM auth.vessels AS v' FROM information_schema.columns WHERE table_name = 'vessels' AND table_schema = 'auth' AND column_name NOT IN ('created_at', 'updated_at');
|
||||||
SELECT v.vessel_id IS NOT NULL AS vessel_id, v.owner_email, v.mmsi, v.name, v.role FROM auth.vessels AS v;
|
SELECT v.vessel_id IS NOT NULL AS vessel_id, v.owner_email, v.mmsi, v.name, v.role FROM auth.vessels AS v;
|
||||||
|
@@ -15,29 +15,27 @@ current_setting |
|
|||||||
|
|
||||||
link vessel and user based on current_setting
|
link vessel and user based on current_setting
|
||||||
-[ RECORD 1 ]----------------------------------------------------------------
|
-[ RECORD 1 ]----------------------------------------------------------------
|
||||||
name | kapla
|
|
||||||
client_id | vessels.urn:mrn:signalk:uuid:5b4f7543-7153-4840-b139-761310b242fd
|
|
||||||
-[ RECORD 2 ]----------------------------------------------------------------
|
|
||||||
name | aava
|
name | aava
|
||||||
client_id | vessels.urn:mrn:imo:mmsi:787654321
|
client_id | vessels.urn:mrn:imo:mmsi:787654321
|
||||||
|
-[ RECORD 2 ]----------------------------------------------------------------
|
||||||
|
name | kapla
|
||||||
|
client_id | vessels.urn:mrn:signalk:uuid:5b4f7543-7153-4840-b139-761310b242fd
|
||||||
|
|
||||||
auth.accounts details
|
auth.accounts details
|
||||||
-[ RECORD 1 ]-----+-----------------------------
|
-[ RECORD 1 ]-----+-----------------------------
|
||||||
public_id | t
|
|
||||||
user_id | t
|
user_id | t
|
||||||
email | demo+kapla@openplotter.cloud
|
email | demo+aava@openplotter.cloud
|
||||||
first | First_kapla
|
first | first_aava
|
||||||
last | Last_kapla
|
last | last_aava
|
||||||
pass | t
|
pass | t
|
||||||
role | user_role
|
role | user_role
|
||||||
telegram |
|
telegram |
|
||||||
pushover_user_key |
|
pushover_user_key |
|
||||||
-[ RECORD 2 ]-----+-----------------------------
|
-[ RECORD 2 ]-----+-----------------------------
|
||||||
public_id | t
|
|
||||||
user_id | t
|
user_id | t
|
||||||
email | demo+aava@openplotter.cloud
|
email | demo+kapla@openplotter.cloud
|
||||||
first | first_aava
|
first | First_kapla
|
||||||
last | last_aava
|
last | Last_kapla
|
||||||
pass | t
|
pass | t
|
||||||
role | user_role
|
role | user_role
|
||||||
telegram |
|
telegram |
|
||||||
|
Reference in New Issue
Block a user