From 6cc13313f1a7dab141308fd94d881922e08ce752 Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Sat, 18 Nov 2023 21:38:55 +0100 Subject: [PATCH] Update tests to match the new anonymous access feature --- tests/index5.js | 26 +++++++++++++------------- tests/sql/anonymous.sql | 20 ++++++++++++++++++++ tests/sql/anonymous.sql.output | 23 +++++++++++++++++++++++ tests/sql/grafana.sql | 2 +- tests/sql/grafana.sql.output | 20 +++++++++----------- 5 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 tests/sql/anonymous.sql create mode 100644 tests/sql/anonymous.sql.output diff --git a/tests/index5.js b/tests/index5.js index 702b203..051837f 100644 --- a/tests/index5.js +++ b/tests/index5.js @@ -28,31 +28,31 @@ var moment = require("moment"); name: "PostgSail unit test kapla", logs: { 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, res: {}, }, log: { 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, res: {}, }, monitoring: { 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, res: {}, }, timelapse: { 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, res: {}, }, export_gpx: { 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, res: {}, }, @@ -62,31 +62,31 @@ var moment = require("moment"); name: "PostgSail unit test, aava", logs: { 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, res: {}, }, log: { - url: "/log_view?id=eq.1", - header: { name: "x-is-public", value: btoa("3,public_logs") }, + url: "/log_view?id=eq.3", + header: { name: "x-is-public", value: btoa("aava,public_logs,3") }, payload: null, res: {}, }, monitoring: { 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, res: {}, }, timelapse: { 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, res: {}, }, export_gpx: { 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, res: {}, }, @@ -106,7 +106,7 @@ var moment = require("moment"); .set(test.logs.header.name, test.logs.header.value) .set("Accept", "application/json") .end(function (err, res) { - res.status.should.equal(401); + res.status.should.equal(404); should.exist(res.header["content-type"]); should.exist(res.header["server"]); res.header["content-type"].should.match(new RegExp("json", "g")); @@ -156,7 +156,7 @@ var moment = require("moment"); .set("Accept", "application/json") .end(function (err, res) { console.log(res.text); - res.status.should.equal(401); + res.status.should.equal(404); should.exist(res.header["content-type"]); should.exist(res.header["server"]); res.header["content-type"].should.match(new RegExp("json", "g")); diff --git a/tests/sql/anonymous.sql b/tests/sql/anonymous.sql new file mode 100644 index 0000000..f402efb --- /dev/null +++ b/tests/sql/anonymous.sql @@ -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'); diff --git a/tests/sql/anonymous.sql.output b/tests/sql/anonymous.sql.output new file mode 100644 index 0000000..e62b4ff --- /dev/null +++ b/tests/sql/anonymous.sql.output @@ -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 + diff --git a/tests/sql/grafana.sql b/tests/sql/grafana.sql index f21b016..3a7ab74 100644 --- a/tests/sql/grafana.sql +++ b/tests/sql/grafana.sql @@ -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; \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' --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; diff --git a/tests/sql/grafana.sql.output b/tests/sql/grafana.sql.output index f232e6e..7f81edd 100644 --- a/tests/sql/grafana.sql.output +++ b/tests/sql/grafana.sql.output @@ -15,29 +15,27 @@ current_setting | link vessel and user based on current_setting -[ RECORD 1 ]---------------------------------------------------------------- -name | kapla -client_id | vessels.urn:mrn:signalk:uuid:5b4f7543-7153-4840-b139-761310b242fd --[ RECORD 2 ]---------------------------------------------------------------- name | aava 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 -[ RECORD 1 ]-----+----------------------------- -public_id | t user_id | t -email | demo+kapla@openplotter.cloud -first | First_kapla -last | Last_kapla +email | demo+aava@openplotter.cloud +first | first_aava +last | last_aava pass | t role | user_role telegram | pushover_user_key | -[ RECORD 2 ]-----+----------------------------- -public_id | t user_id | t -email | demo+aava@openplotter.cloud -first | first_aava -last | last_aava +email | demo+kapla@openplotter.cloud +first | First_kapla +last | Last_kapla pass | t role | user_role telegram |