-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: application-server module various fixes
- rename "application-server" in "administration-console-api" - administration-console-api uses matrix application server instance of tom-server instead of extend matrix-application-server package - use postgresql instead of sqlite for administration-console-api integration tests
- Loading branch information
Jordy Cabannes
committed
Apr 12, 2024
1 parent
9c0d6fe
commit 042f8fc
Showing
45 changed files
with
1,917 additions
and
1,395 deletions.
There are no files selected for viewing
This file contains 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 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
79 changes: 79 additions & 0 deletions
79
packages/tom-server/src/administration-console-api/__testData__/build-userdb.ts
This file contains 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,79 @@ | ||
import sqlite3 from 'sqlite3' | ||
import { type Config } from '../../types' | ||
|
||
let created = false | ||
|
||
const createQuery = | ||
'CREATE TABLE users (uid varchar(8), mobile varchar(12), mail varchar(32), sn varchar(32))' | ||
const insertQueries = [ | ||
"INSERT INTO users VALUES('dwho', '33612345678', '[email protected]', 'Dwho')", | ||
"INSERT INTO users VALUES('rtyler', '33687654321', '[email protected]', 'Rtyler')" | ||
] | ||
|
||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
export const buildUserDB = (conf: Config): Promise<void> => { | ||
if (created) return Promise.resolve() | ||
return new Promise((resolve, reject) => { | ||
const matrixDb = new sqlite3.Database(conf.matrix_database_host) | ||
matrixDb.run( | ||
'CREATE TABLE users (name text, desactivated text, admin integer)', | ||
(err) => { | ||
if (err != null) { | ||
reject(err) | ||
} else { | ||
matrixDb.run( | ||
"INSERT INTO users VALUES('@dwho:example.com', '', 0)", | ||
(err) => { | ||
if (err != null) { | ||
reject(err) | ||
} else { | ||
matrixDb.close((err) => { | ||
/* istanbul ignore if */ | ||
if (err != null) { | ||
console.error(err) | ||
reject(err) | ||
} else { | ||
const userDb = new sqlite3.Database( | ||
conf.userdb_host as string | ||
) | ||
userDb.run(createQuery, (err) => { | ||
if (err != null) { | ||
reject(err) | ||
} else { | ||
Promise.all( | ||
insertQueries.map( | ||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
(query) => | ||
new Promise((_resolve, _reject) => { | ||
userDb.run(query, (err) => { | ||
err != null ? _reject(err) : _resolve(true) | ||
}) | ||
}) | ||
) | ||
) | ||
.then(() => { | ||
userDb.close((err) => { | ||
/* istanbul ignore if */ | ||
if (err != null) { | ||
console.error(err) | ||
reject(err) | ||
} else { | ||
created = true | ||
resolve() | ||
} | ||
}) | ||
}) | ||
|
||
.catch(reject) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
) | ||
}) | ||
} |
95 changes: 95 additions & 0 deletions
95
packages/tom-server/src/administration-console-api/__testData__/db/init-llng-db.sh
This file contains 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,95 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
DATABASE=${PG_DATABASE:-lemonldapng} | ||
USER=${PG_USER:-lemonldap} | ||
PASSWORD=${PG_PASSWORD:-lemonldap} | ||
TABLE=${PG_TABLE:-lmConfig} | ||
PTABLE=${PG_PERSISTENT_SESSIONS_TABLE:-psessions} | ||
STABLE=${PG_SESSIONS_TABLE:-sessions} | ||
SAMLTABLE=${PG_SAML_TABLE:-samlsessions} | ||
OIDCTABLE=${PG_OIDC_TABLE:-oidcsessions} | ||
CASTABLE=${PG_CAS_TABLE:-cassessions} | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE USER $USER PASSWORD '$PASSWORD'; | ||
CREATE DATABASE $DATABASE; | ||
EOSQL | ||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$DATABASE" <<-EOSQL | ||
CREATE TABLE $TABLE ( | ||
cfgNum integer not null primary key, | ||
data text | ||
); | ||
GRANT ALL PRIVILEGES ON TABLE $TABLE TO $USER; | ||
CREATE TABLE $PTABLE ( | ||
id varchar(64) not null primary key, | ||
a_session jsonb | ||
); | ||
CREATE INDEX i_p__session_kind ON psessions ((a_session ->> '_session_kind')); | ||
CREATE INDEX i_p__httpSessionType ON psessions ((a_session ->> '_httpSessionType')); | ||
CREATE INDEX i_p__session_uid ON psessions ((a_session ->> '_session_uid')); | ||
CREATE INDEX i_p_ipAddr ON psessions ((a_session ->> 'ipAddr')); | ||
CREATE INDEX i_p__whatToTrace ON psessions ((a_session ->> '_whatToTrace')); | ||
GRANT ALL PRIVILEGES ON TABLE $PTABLE TO $USER; | ||
CREATE UNLOGGED TABLE $STABLE ( | ||
id varchar(64) not null primary key, | ||
a_session jsonb | ||
); | ||
CREATE INDEX i_s__whatToTrace ON sessions ((a_session ->> '_whatToTrace')); | ||
CREATE INDEX i_s__session_kind ON sessions ((a_session ->> '_session_kind')); | ||
CREATE INDEX i_s__utime ON sessions ((cast (a_session ->> '_utime' as bigint))); | ||
CREATE INDEX i_s_ipAddr ON sessions ((a_session ->> 'ipAddr')); | ||
CREATE INDEX i_s__httpSessionType ON sessions ((a_session ->> '_httpSessionType')); | ||
CREATE INDEX i_s_user ON sessions ((a_session ->> 'user')); | ||
GRANT ALL PRIVILEGES ON TABLE $STABLE TO $USER; | ||
CREATE UNLOGGED TABLE $SAMLTABLE ( | ||
id varchar(64) not null primary key, | ||
a_session jsonb | ||
); | ||
CREATE INDEX i_a__session_kind ON $SAMLTABLE ((a_session ->> '_session_kind')); | ||
CREATE INDEX i_a__utime ON $SAMLTABLE ((cast(a_session ->> '_utime' as bigint))); | ||
CREATE INDEX i_a_ProxyID ON $SAMLTABLE ((a_session ->> 'ProxyID')); | ||
CREATE INDEX i_a__nameID ON $SAMLTABLE ((a_session ->> '_nameID')); | ||
CREATE INDEX i_a__assert_id ON $SAMLTABLE ((a_session ->> '_assert_id')); | ||
CREATE INDEX i_a__art_id ON $SAMLTABLE ((a_session ->> '_art_id')); | ||
CREATE INDEX i_a__saml_id ON $SAMLTABLE ((a_session ->> '_saml_id')); | ||
GRANT ALL PRIVILEGES ON TABLE $SAMLTABLE TO $USER; | ||
CREATE UNLOGGED TABLE $OIDCTABLE ( | ||
id varchar(64) not null primary key, | ||
a_session jsonb | ||
); | ||
CREATE INDEX i_o__session_kind ON $OIDCTABLE ((a_session ->> '_session_kind')); | ||
CREATE INDEX i_o__utime ON $OIDCTABLE ((cast(a_session ->> '_utime' as bigint ))); | ||
GRANT ALL PRIVILEGES ON TABLE $OIDCTABLE TO $USER; | ||
CREATE UNLOGGED TABLE $CASTABLE ( | ||
id varchar(64) not null primary key, | ||
a_session jsonb | ||
); | ||
CREATE INDEX i_c__session_kind ON $CASTABLE ((a_session ->> '_session_kind')); | ||
CREATE INDEX i_c__utime ON $CASTABLE ((cast(a_session ->> '_utime' as bigint))); | ||
CREATE INDEX i_c__cas_id ON $CASTABLE ((a_session ->> '_cas_id')); | ||
CREATE INDEX i_c_pgtIou ON $CASTABLE ((a_session ->> 'pgtIou')); | ||
GRANT ALL PRIVILEGES ON TABLE $CASTABLE TO $USER; | ||
EOSQL | ||
|
||
if test -e /llng-conf/conf.json; then | ||
SERIALIZED=`perl -MJSON -e '$/=undef; | ||
open F, "/llng-conf/conf.json" or die $!; | ||
$a=JSON::from_json(<F>); | ||
$a->{cfgNum}=1; | ||
$a=JSON::to_json($a); | ||
$a=~s/'\''/'\'\''/g; | ||
$a =~ s/\\\\/\\\\\\\\/g; | ||
print $a;'` | ||
echo "set val '$SERIALIZED'" >&2 | ||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$DATABASE" <<-EOSQL | ||
\\set val '$SERIALIZED' | ||
INSERT INTO $TABLE (cfgNum, data) VALUES (1, :'val'); | ||
\\unset val | ||
EOSQL | ||
fi |
23 changes: 23 additions & 0 deletions
23
...ver/src/administration-console-api/__testData__/db/init-synapse-and-create-users-table.sh
This file contains 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,23 @@ | ||
#!/bin/sh | ||
|
||
psql -U postgres <<-EOSQL | ||
CREATE USER synapse PASSWORD 'synapse!1'; | ||
CREATE DATABASE synapse TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse'; | ||
EOSQL | ||
psql -v ON_ERROR_STOP=1 --username "synapse" --dbname "synapse" <<-EOSQL | ||
CREATE TABLE users ( | ||
name text, | ||
password_hash text, | ||
creation_ts bigint, | ||
admin smallint DEFAULT 0 NOT NULL, | ||
upgrade_ts bigint, | ||
is_guest smallint DEFAULT 0 NOT NULL, | ||
appservice_id text, | ||
consent_version text, | ||
consent_server_notice_sent text, | ||
user_type text, | ||
deactivated smallint DEFAULT 0 NOT NULL, | ||
shadow_banned boolean, | ||
consent_ts bigint | ||
); | ||
EOSQL |
6 changes: 6 additions & 0 deletions
6
packages/tom-server/src/administration-console-api/__testData__/db/init-synapse-db.sh
This file contains 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,6 @@ | ||
#!/bin/sh | ||
|
||
psql -U postgres <<-EOSQL | ||
CREATE USER synapse PASSWORD 'synapse!1'; | ||
CREATE DATABASE synapse TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse'; | ||
EOSQL |
6 changes: 6 additions & 0 deletions
6
packages/tom-server/src/administration-console-api/__testData__/db/init-twake-db.sh
This file contains 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,6 @@ | ||
#!/bin/sh | ||
|
||
psql -U postgres <<-EOSQL | ||
CREATE USER twake PASSWORD 'twake!1'; | ||
CREATE DATABASE twakedb TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake'; | ||
EOSQL |
Oops, something went wrong.