Skip to content

Commit

Permalink
Update tests to match the new anonymous access feature
Browse files Browse the repository at this point in the history
  • Loading branch information
xbgmsharp committed Nov 18, 2023
1 parent fdb466a commit 6cc1331
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
26 changes: 13 additions & 13 deletions tests/index5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
},
Expand All @@ -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: {},
},
Expand All @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down
20 changes: 20 additions & 0 deletions tests/sql/anonymous.sql
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions tests/sql/anonymous.sql.output
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/sql/grafana.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 9 additions & 11 deletions tests/sql/grafana.sql.output
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit 6cc1331

Please sign in to comment.