Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69d908bac3 | ||
|
|
7d2faba4f2 | ||
|
|
e9b59fc1dd | ||
|
|
1ab7bd4ae1 | ||
|
|
d83591c8a4 | ||
|
|
0cab4e8530 | ||
|
|
b678c098cb | ||
|
|
e3ee24c131 | ||
|
|
8e0b8b737b |
+7
-7
@@ -1,10 +1,10 @@
|
|||||||
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
||||||
DB_NAME=textsender_auth_db
|
DB_AUTH_NAME=textsender_auth_db
|
||||||
DB_USER=textsender_auth
|
DB_AUTH_USER=textsender_auth
|
||||||
DB_PASSWORD=password
|
DB_AUTH_PASSWORD=password
|
||||||
DB_HOST=auth_db
|
DB_AUTH_HOST=auth_db
|
||||||
DB_PORT=5432
|
DB_AUTH_PORT=5432
|
||||||
DB_SSLMODE=disable
|
DB_AUTH_SSLMODE=disable
|
||||||
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}
|
DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
|
||||||
ENABLE_REGISTRATION=true
|
ENABLE_REGISTRATION=true
|
||||||
ALLOWED_ORIGINS="http://textsender.com"
|
ALLOWED_ORIGINS="http://textsender.com"
|
||||||
|
|||||||
+7
-7
@@ -1,10 +1,10 @@
|
|||||||
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
||||||
DB_NAME=textsender_auth_db
|
DB_AUTH_NAME=textsender_auth_db
|
||||||
DB_USER=textsender_auth
|
DB_AUTH_USER=textsender_auth
|
||||||
DB_PASSWORD=password
|
DB_AUTH_PASSWORD=password
|
||||||
DB_HOST=localhost
|
DB_AUTH_HOST=localhost
|
||||||
DB_PORT=5432
|
DB_AUTH_PORT=5432
|
||||||
DB_SSLMODE=disable
|
DB_AUTH_SSLMODE=disable
|
||||||
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}
|
DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
|
||||||
ENABLE_REGISTRATION=true
|
ENABLE_REGISTRATION=true
|
||||||
ALLOWED_ORIGINS="http://textsender.com"
|
ALLOWED_ORIGINS="http://textsender.com"
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
name: Rust Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
|
|
||||||
|
cargo check
|
||||||
|
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
@@ -4,9 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
@@ -16,7 +13,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -41,6 +38,7 @@ jobs:
|
|||||||
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
||||||
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
||||||
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
|
POSTGRES_PORT: ${{ secrets.DB_PORT || 5432 }}
|
||||||
# Options to wait until the database is ready
|
# Options to wait until the database is ready
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
@@ -52,7 +50,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
# --- Add this step for explicit verification ---
|
# --- Add this step for explicit verification ---
|
||||||
- name: Verify Docker Environment
|
- name: Verify Docker Environment
|
||||||
@@ -71,7 +69,7 @@ jobs:
|
|||||||
- name: Run tests
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
# Define DATABASE_URL for tests to use
|
# Define DATABASE_URL for tests to use
|
||||||
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:${{ secrets.DB_PORT || 5432 }}/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
RUST_LOG: info # Optional: configure test log level
|
RUST_LOG: info # Optional: configure test log level
|
||||||
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||||
# Make SSH agent available if tests fetch private dependencies
|
# Make SSH agent available if tests fetch private dependencies
|
||||||
@@ -95,7 +93,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
@@ -115,7 +113,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
@@ -135,7 +133,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/textsender-auth
|
|
||||||
|
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.docker
|
.env.docker
|
||||||
|
|||||||
Generated
+56
-59
@@ -250,9 +250,9 @@ checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.11.1"
|
version = "2.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
@@ -308,9 +308,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.63"
|
version = "1.2.64"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f"
|
checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"shlex",
|
"shlex",
|
||||||
@@ -469,7 +469,6 @@ version = "0.5.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"powerfmt",
|
|
||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -854,9 +853,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.4.1"
|
version = "1.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0"
|
checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"itoa",
|
"itoa",
|
||||||
@@ -1078,13 +1077,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.99"
|
version = "0.3.102"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11"
|
checksum = "03d04c30968dffe80775bd4d7fb676131cd04a1fb46d2686dbffbaec2d9dfd31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"once_cell",
|
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1148,7 +1146,7 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
"libc",
|
"libc",
|
||||||
"plain",
|
"plain",
|
||||||
"redox_syscall 0.8.0",
|
"redox_syscall 0.8.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1184,9 +1182,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.30"
|
version = "0.4.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5"
|
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"value-bag",
|
"value-bag",
|
||||||
]
|
]
|
||||||
@@ -1209,9 +1207,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.8.1"
|
version = "2.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
|
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
@@ -1336,9 +1334,9 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.10.80"
|
version = "0.10.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967"
|
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
@@ -1367,9 +1365,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.9.116"
|
version = "0.9.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4"
|
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -1618,18 +1616,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c7591fa2c6b601dfcfe5f043f65a1c39fcdf50efefcd7f1572e538c1f4b398d"
|
checksum = "5b44b894f2a6e36457d665d1e08c3866add6ed5e70050c1b4ba8a8ddedb02ce7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.12.3"
|
version = "1.12.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
|
checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -1650,9 +1648,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.8.10"
|
version = "0.8.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsa"
|
name = "rsa"
|
||||||
@@ -1914,9 +1912,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.15.1"
|
version = "1.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@@ -2213,7 +2211,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textsender_auth"
|
name = "textsender_auth"
|
||||||
version = "0.1.17"
|
version = "0.1.23"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"async-std",
|
"async-std",
|
||||||
@@ -2240,8 +2238,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textsender_models"
|
name = "textsender_models"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/textsender-models.git?tag=v0.3.0#d504108745b7b97a02eac24e16763cdb5e731f2b"
|
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.4.0#2722af5589023db819554a97c1f596d9e735fe96"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const_format",
|
"const_format",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
@@ -2284,12 +2282,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.47"
|
version = "0.3.49"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
|
checksum = "711a53c2d47bbd818258c498c8dbfe186a2526c631495cfe7e078567f86b8469"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
"itoa",
|
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
@@ -2299,15 +2296,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time-core"
|
name = "time-core"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
|
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time-macros"
|
name = "time-macros"
|
||||||
version = "0.2.27"
|
version = "0.2.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215"
|
checksum = "71c652a3727a9cbb9a02f707f530b618ce00d0ccd762009c8c23bd191df3c17d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-conv",
|
"num-conv",
|
||||||
"time-core",
|
"time-core",
|
||||||
@@ -2600,9 +2597,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.23.2"
|
version = "1.23.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7"
|
checksum = "144d6b123cef80b301b8f72a9e2ca4370ddec21950d0a103dd22c437006d2db7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.4.2",
|
"getrandom 0.4.2",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@@ -2652,9 +2649,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasip2"
|
name = "wasip2"
|
||||||
version = "1.0.3+wasi-0.2.9"
|
version = "1.0.4+wasi-0.2.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6"
|
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wit-bindgen 0.57.1",
|
"wit-bindgen 0.57.1",
|
||||||
]
|
]
|
||||||
@@ -2676,9 +2673,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.122"
|
version = "0.2.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409"
|
checksum = "8ddb3f79143bced6de84270411622a2699cee572fc0875aeaf1e7867cf9fca1a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -2689,9 +2686,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-futures"
|
name = "wasm-bindgen-futures"
|
||||||
version = "0.4.72"
|
version = "0.4.75"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f"
|
checksum = "503b14d284f2c8dac03b819967e155ea753f573586193b2b2c95990cb5d69280"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@@ -2699,9 +2696,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.122"
|
version = "0.2.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6"
|
checksum = "4e21a184b13fb19e157296e2c46056aec9092264fab83e4ba59e68c61b323c3d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@@ -2709,9 +2706,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.122"
|
version = "0.2.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e"
|
checksum = "fecefd9c35bd935a20fc3fc344b5f29138961e4f47fb03297d88f2587afb5ebd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -2722,9 +2719,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.122"
|
version = "0.2.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437"
|
checksum = "23939e44bb9a5d7576fa2b563dc2e136628f1224e88a8deed09e04858b77871f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -2965,9 +2962,9 @@ checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yoke"
|
name = "yoke"
|
||||||
version = "0.8.2"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca"
|
checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
"yoke-derive",
|
"yoke-derive",
|
||||||
@@ -2988,18 +2985,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.8.50"
|
version = "0.8.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1"
|
checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy-derive",
|
"zerocopy-derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy-derive"
|
name = "zerocopy-derive"
|
||||||
version = "0.8.50"
|
version = "0.8.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639"
|
checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -3029,9 +3026,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.8.2"
|
version = "1.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerotrie"
|
name = "zerotrie"
|
||||||
|
|||||||
+9
-9
@@ -1,27 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "textsender_auth"
|
name = "textsender_auth"
|
||||||
version = "0.1.17"
|
version = "0.1.23"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.96"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.8.9" }
|
axum = { version = "0.8.9" }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.149" }
|
serde_json = { version = "1.0.150" }
|
||||||
tokio = { version = "1.52.2", features = ["rt-multi-thread"] }
|
tokio = { version = "1.52.3", features = ["rt-multi-thread"] }
|
||||||
tracing-subscriber = { version = "0.3.23" }
|
tracing-subscriber = { version = "0.3.23" }
|
||||||
tower = { version = "0.5.3", features = ["full"] }
|
tower = { version = "0.5.3", features = ["full"] }
|
||||||
tower-http = { version = "0.6.10", features = ["cors"] }
|
tower-http = { version = "0.6.11", features = ["cors"] }
|
||||||
hyper = { version = "1.9.0" }
|
hyper = { version = "1.10.1" }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
||||||
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
||||||
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
|
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
|
||||||
rand = { version = "0.10.1" }
|
rand = { version = "0.10.1" }
|
||||||
time = { version = "0.3.47", features = ["macros", "serde"] }
|
time = { version = "0.3.49", features = ["macros", "serde"] }
|
||||||
josekit = { version = "0.10.3" }
|
josekit = { version = "0.10.3" }
|
||||||
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0" }
|
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.0", features = ["config", "user"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
http-body-util = { version = "0.1.3" }
|
http-body-util = { version = "0.1.3" }
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
# Stage 1: Build the application
|
# Stage 1: Build the application
|
||||||
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
||||||
# Using slim variant for smaller base image
|
# Using slim variant for smaller base image
|
||||||
FROM rust:1.95 as builder
|
FROM rust:1.96 as builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|||||||
+5
-4
@@ -23,13 +23,14 @@ services:
|
|||||||
container_name: textsender_auth_db # Optional: Give the container a specific name
|
container_name: textsender_auth_db # Optional: Give the container a specific name
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${DB_USER:-textsender_op}
|
POSTGRES_USER: ${DB_AUTH_USER:-textsender_op}
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
|
POSTGRES_PASSWORD: ${DB_AUTH_PASSWORD:-password}
|
||||||
POSTGRES_DB: ${DB_NAME:-textsender_auth_db}
|
POSTGRES_DB: ${DB_AUTH_NAME:-textsender_auth_db}
|
||||||
volumes:
|
volumes:
|
||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data:/var/lib/postgresql
|
- postgres_data:/var/lib/postgresql
|
||||||
ports: []
|
ports:
|
||||||
|
- "5433:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
||||||
|
|||||||
@@ -32,6 +32,51 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
|
pub struct RefreshTokenRequest {
|
||||||
|
pub access_token: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
|
pub struct UpdatePasswordRequest {
|
||||||
|
pub user_id: uuid::Uuid,
|
||||||
|
pub current_password: String,
|
||||||
|
pub updated_password: String,
|
||||||
|
pub confirmed_password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UpdatePasswordRequest {
|
||||||
|
pub fn is_valid(&self) -> bool {
|
||||||
|
if self.user_id.is_nil()
|
||||||
|
|| self.current_password.is_empty()
|
||||||
|
|| self.updated_password.is_empty()
|
||||||
|
|| self.confirmed_password.is_empty()
|
||||||
|
{
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
self.updated_password == self.confirmed_password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
|
pub struct UserUpdateNameRequest {
|
||||||
|
pub user_id: uuid::Uuid,
|
||||||
|
pub firstname: String,
|
||||||
|
pub lastname: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserUpdateNameRequest {
|
||||||
|
pub fn is_valid(&self) -> (bool, Option<String>) {
|
||||||
|
if self.user_id.is_nil() || self.firstname.is_empty() || self.lastname.is_empty() {
|
||||||
|
let reason = String::from("Missing fields");
|
||||||
|
(false, Some(reason))
|
||||||
|
} else {
|
||||||
|
(true, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
@@ -57,6 +102,24 @@ pub mod response {
|
|||||||
let _parsed_body: LoginResponse = serde_json::from_slice(&body).unwrap();
|
let _parsed_body: LoginResponse = serde_json::from_slice(&body).unwrap();
|
||||||
todo!("Add code to convert axum::Response to this type");
|
todo!("Add code to convert axum::Response to this type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct RefreshTokenResponse {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<textsender_models::token::LoginResult>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct UpdatePasswordResponse {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct UserUpdateNameResponse {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<textsender_models::user::User>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Endpoint for a user login
|
/// Endpoint for a user login
|
||||||
@@ -337,3 +400,431 @@ pub async fn service_user_login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Endpoint for service user login
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = super::endpoints::REFRESH_TOKEN,
|
||||||
|
request_body(
|
||||||
|
content = request::RefreshTokenRequest,
|
||||||
|
description = "Data required refresh token",
|
||||||
|
content_type = "application/json"
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Service uuser login successful", body = response::RefreshTokenResponse),
|
||||||
|
(status = 400, description = "Bad data", body = response::RefreshTokenResponse),
|
||||||
|
(status = 500, description = "Something went wrong", body = response::RefreshTokenResponse)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn refresh_token(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::Json(payload): axum::Json<request::RefreshTokenRequest>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<response::RefreshTokenResponse>,
|
||||||
|
) {
|
||||||
|
if payload.access_token.is_empty() {
|
||||||
|
let reason = String::from("Access token not provided");
|
||||||
|
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: reason,
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let key = textsender_models::envy::environment::get_secret_key()
|
||||||
|
.await
|
||||||
|
.value;
|
||||||
|
if token_stuff::verify_token(&key, &payload.access_token) {
|
||||||
|
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||||
|
Ok(id) => {
|
||||||
|
let generate_service_token = |id, key| -> (Option<String>, Option<i64>) {
|
||||||
|
match token_stuff::create_service_refresh_token(key, id) {
|
||||||
|
Ok((token, issued)) => (Some(token), Some(issued)),
|
||||||
|
Err(_err) => (None, None),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut response = response::RefreshTokenResponse {
|
||||||
|
message: String::new(),
|
||||||
|
data: Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match repo::user::get_with_id(&pool, &id).await {
|
||||||
|
Ok(_user) => {
|
||||||
|
let (refresh_token, issued) = generate_service_token(&id, &key);
|
||||||
|
match refresh_token {
|
||||||
|
Some(token) => match issued {
|
||||||
|
Some(issued_at) => {
|
||||||
|
response.message =
|
||||||
|
String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||||
|
let lr = textsender_models::token::LoginResult {
|
||||||
|
user_id: id,
|
||||||
|
access_token: token,
|
||||||
|
issued_at,
|
||||||
|
token_type: String::from(
|
||||||
|
textsender_models::token::TOKEN_TYPE,
|
||||||
|
),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
response.data.push(lr);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
None => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: String::from("Issued at not returned"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
None => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: String::from("Refresh token not generated"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("Unable to find user, checking service user: {err:?}");
|
||||||
|
match repo::service::get(&pool, &id).await {
|
||||||
|
Ok(_service_user) => {
|
||||||
|
let (refresh_token, issued) = generate_service_token(&id, &key);
|
||||||
|
match refresh_token {
|
||||||
|
Some(token) => match issued {
|
||||||
|
Some(issued_at) => {
|
||||||
|
response.message = String::from(
|
||||||
|
super::messages::SUCCESSFUL_MESSAGE,
|
||||||
|
);
|
||||||
|
let lr = textsender_models::token::LoginResult {
|
||||||
|
user_id: id,
|
||||||
|
access_token: token,
|
||||||
|
issued_at,
|
||||||
|
token_type: String::from(
|
||||||
|
textsender_models::token::TOKEN_TYPE,
|
||||||
|
),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
response.data.push(lr);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
None => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: String::from("Issued at not returned"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
None => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: String::from(
|
||||||
|
"Refresh token not generated",
|
||||||
|
),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::RefreshTokenResponse {
|
||||||
|
message: String::from("Unable to verify token"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint for a updating password
|
||||||
|
#[utoipa::path(
|
||||||
|
patch,
|
||||||
|
path = super::endpoints::UPDATE_PASSWORD,
|
||||||
|
request_body(
|
||||||
|
content = request::UpdatePasswordRequest,
|
||||||
|
description = "Data required to update password",
|
||||||
|
content_type = "application/json"
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "User login successful", body = response::UpdatePasswordResponse),
|
||||||
|
(status = 400, description = "Bad data", body = response::UpdatePasswordResponse),
|
||||||
|
(status = 500, description = "Something went wrong", body = response::UpdatePasswordResponse)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn update_password(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::Json(payload): axum::Json<request::UpdatePasswordRequest>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<response::UpdatePasswordResponse>,
|
||||||
|
) {
|
||||||
|
if !payload.is_valid() {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: String::from("Invalid passwords"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let verify_password = |current_password, hashed_password| -> Result<bool, std::io::Error> {
|
||||||
|
match hashing::verify_password(current_password, hashed_password) {
|
||||||
|
Ok(matches) => Ok(matches),
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match repo::user::get_with_id(&pool, &payload.user_id).await {
|
||||||
|
Ok(user) => {
|
||||||
|
let hashed_password = user.password.clone();
|
||||||
|
match verify_password(&payload.current_password, hashed_password) {
|
||||||
|
Ok(matches) => {
|
||||||
|
if matches {
|
||||||
|
let (generate_salt, mut salt) = super::register::generate_the_salt();
|
||||||
|
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||||
|
let updated_hashed_password = match hashing::hash_password(
|
||||||
|
&payload.updated_password,
|
||||||
|
&generate_salt,
|
||||||
|
) {
|
||||||
|
Ok(hashed) => hashed,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match repo::user::update_password(
|
||||||
|
&pool,
|
||||||
|
&user,
|
||||||
|
&updated_hashed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => (
|
||||||
|
axum::http::StatusCode::OK,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
||||||
|
data: vec![user.id],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: String::from("Issue updating password"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("No User found, trying Service User: {err:?}");
|
||||||
|
|
||||||
|
// Try service user
|
||||||
|
match repo::service::get(&pool, &payload.user_id).await {
|
||||||
|
Ok(service_user) => {
|
||||||
|
let hashed_password = service_user.passphrase.clone();
|
||||||
|
match verify_password(&payload.current_password, hashed_password) {
|
||||||
|
Ok(matches) => {
|
||||||
|
if matches {
|
||||||
|
let (generate_salt, mut salt) =
|
||||||
|
super::register::generate_the_salt();
|
||||||
|
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||||
|
let updated_hashed_password = match hashing::hash_password(
|
||||||
|
&payload.updated_password,
|
||||||
|
&generate_salt,
|
||||||
|
) {
|
||||||
|
Ok(hashed) => hashed,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match repo::service::update_passphrase(
|
||||||
|
&pool,
|
||||||
|
&service_user,
|
||||||
|
&updated_hashed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => (
|
||||||
|
axum::http::StatusCode::OK,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: String::from(
|
||||||
|
super::messages::SUCCESSFUL_MESSAGE,
|
||||||
|
),
|
||||||
|
data: vec![service_user.id],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: String::from("Issue updating password"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint for a updating password
|
||||||
|
#[utoipa::path(
|
||||||
|
patch,
|
||||||
|
path = super::endpoints::UPDATE_USER_NAME,
|
||||||
|
request_body(
|
||||||
|
content = request::UserUpdateNameRequest,
|
||||||
|
description = "Data required to update name of a user",
|
||||||
|
content_type = "application/json"
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Names were updated", body = response::UserUpdateNameResponse),
|
||||||
|
(status = 304, description = "Nothing to change", body = response::UserUpdateNameResponse),
|
||||||
|
(status = 400, description = "Bad data", body = response::UserUpdateNameResponse),
|
||||||
|
(status = 500, description = "Something went wrong", body = response::UserUpdateNameResponse)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn update_name_of_user(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::Json(payload): axum::Json<request::UserUpdateNameRequest>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<response::UserUpdateNameResponse>,
|
||||||
|
) {
|
||||||
|
let (valid_request, reason) = payload.is_valid();
|
||||||
|
if !valid_request {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
|
axum::Json(response::UserUpdateNameResponse {
|
||||||
|
message: reason.unwrap_or_default(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
match repo::user::get_with_id(&pool, &payload.user_id).await {
|
||||||
|
Ok(user) => {
|
||||||
|
if user.firstname == payload.firstname || user.lastname == payload.lastname {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::NOT_MODIFIED,
|
||||||
|
axum::Json(response::UserUpdateNameResponse {
|
||||||
|
message: String::from("No change"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
match repo::user::update_name(
|
||||||
|
&pool,
|
||||||
|
&user.id,
|
||||||
|
&payload.firstname,
|
||||||
|
&payload.lastname,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => (
|
||||||
|
axum::http::StatusCode::OK,
|
||||||
|
axum::Json(response::UserUpdateNameResponse {
|
||||||
|
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
||||||
|
data: vec![textsender_models::user::User {
|
||||||
|
id: user.id,
|
||||||
|
phone_number: user.phone_number,
|
||||||
|
firstname: payload.firstname,
|
||||||
|
lastname: payload.lastname,
|
||||||
|
username: user.username,
|
||||||
|
created: user.created,
|
||||||
|
last_login: user.last_login,
|
||||||
|
..Default::default()
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UserUpdateNameResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UserUpdateNameResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,4 +13,10 @@ pub mod endpoints {
|
|||||||
pub const REGISTER_SERVICE_USER: &str = "/api/v1/service/register";
|
pub const REGISTER_SERVICE_USER: &str = "/api/v1/service/register";
|
||||||
/// Endpoint constant for service login user
|
/// Endpoint constant for service login user
|
||||||
pub const LOGIN_SERVICE_USER: &str = "/api/v1/service/login";
|
pub const LOGIN_SERVICE_USER: &str = "/api/v1/service/login";
|
||||||
|
/// Endpoint constant for refresh token
|
||||||
|
pub const REFRESH_TOKEN: &str = "/api/v1/token/refresh";
|
||||||
|
/// Endpoint constant for updating password
|
||||||
|
pub const UPDATE_PASSWORD: &str = "/api/v1/user/password/update";
|
||||||
|
/// Endpoint constant for updating user's name
|
||||||
|
pub const UPDATE_USER_NAME: &str = "/api/v1/user/name/update";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ pub mod response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_the_salt() -> (
|
pub fn generate_the_salt() -> (
|
||||||
argon2::password_hash::SaltString,
|
argon2::password_hash::SaltString,
|
||||||
textsender_models::user::Salt,
|
textsender_models::user::Salt,
|
||||||
) {
|
) {
|
||||||
|
|||||||
+13
-1
@@ -8,7 +8,7 @@ pub mod token_stuff;
|
|||||||
pub mod init {
|
pub mod init {
|
||||||
use axum::{
|
use axum::{
|
||||||
Router,
|
Router,
|
||||||
routing::{get, post},
|
routing::{get, patch, post},
|
||||||
};
|
};
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
@@ -106,6 +106,18 @@ pub mod init {
|
|||||||
callers::endpoints::LOGIN_SERVICE_USER,
|
callers::endpoints::LOGIN_SERVICE_USER,
|
||||||
post(callers::login::service_user_login),
|
post(callers::login::service_user_login),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
callers::endpoints::REFRESH_TOKEN,
|
||||||
|
post(callers::login::refresh_token),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
callers::endpoints::UPDATE_PASSWORD,
|
||||||
|
patch(callers::login::update_password),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
callers::endpoints::UPDATE_USER_NAME,
|
||||||
|
patch(callers::login::update_name_of_user),
|
||||||
|
)
|
||||||
.layer(cors::configure_cors().await)
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,36 @@ pub mod user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_with_id(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<textsender_models::user::User, sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, username, password, phone_number, salt_id, firstname, lastname, created, last_login FROM "user" WHERE id = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(id)
|
||||||
|
.fetch_optional(pool)
|
||||||
|
.await {
|
||||||
|
Ok(r) => match r {
|
||||||
|
Some(r) => Ok(textsender_models::user::User {
|
||||||
|
id: r.try_get("id")?,
|
||||||
|
username: r.try_get("username")?,
|
||||||
|
password: r.try_get("password")?,
|
||||||
|
phone_number: r.try_get("phone_number")?,
|
||||||
|
salt_id: r.try_get("salt_id")?,
|
||||||
|
firstname: r.try_get("firstname")?,
|
||||||
|
lastname: r.try_get("lastname")?,
|
||||||
|
created: r.try_get("created")?,
|
||||||
|
last_login: r.try_get("last_login")?,
|
||||||
|
}),
|
||||||
|
None => Err(sqlx::Error::RowNotFound),
|
||||||
|
},
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_last_login(
|
pub async fn update_last_login(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
user: &textsender_models::user::User,
|
user: &textsender_models::user::User,
|
||||||
@@ -74,6 +104,60 @@ pub mod user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_password(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
user: &textsender_models::user::User,
|
||||||
|
updated_hashed_password: &String,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
UPDATE "user" SET password = $1 WHERE id = $2
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(updated_hashed_password)
|
||||||
|
.bind(user.id)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
if row.rows_affected() > 0 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(sqlx::Error::RowNotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_name(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
firstname: &str,
|
||||||
|
lastname: &str,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
UPDATE "user" SET firstname = $1, lastname = $2 WHERE id = $3
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(firstname)
|
||||||
|
.bind(lastname)
|
||||||
|
.bind(id)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
if row.rows_affected() > 0 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(sqlx::Error::RowNotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn exists(pool: &sqlx::PgPool, username: &String) -> Result<bool, sqlx::Error> {
|
pub async fn exists(pool: &sqlx::PgPool, username: &String) -> Result<bool, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
|
|||||||
@@ -49,6 +49,42 @@ pub async fn get_passphrase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<textsender_models::user::ServiceUser, sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"SELECT id, username, passphrase, created, last_login, salt_id FROM "service_user" WHERE id = $1"#
|
||||||
|
).bind(id)
|
||||||
|
.fetch_one(pool).await {
|
||||||
|
Ok(row) => {
|
||||||
|
let last_login: Option<time::OffsetDateTime> = match row.try_get("last_login") {
|
||||||
|
Ok(login) => {
|
||||||
|
Some(login)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let service_user = textsender_models::user::ServiceUser {
|
||||||
|
id: row.try_get("id")?,
|
||||||
|
username: row.try_get("username")?,
|
||||||
|
passphrase: row.try_get("passphrase")?,
|
||||||
|
created: row.try_get("created")?,
|
||||||
|
last_login,
|
||||||
|
salt_id: row.try_get("salt_id")?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(service_user)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_with_username(
|
pub async fn get_with_username(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
username: &String,
|
username: &String,
|
||||||
@@ -118,6 +154,32 @@ pub async fn update_last_login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_passphrase(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
user: &textsender_models::user::ServiceUser,
|
||||||
|
updated_hashed_passphrase: &String,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
UPDATE "service_user" SET passphrase = $1 WHERE id = $2
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(updated_hashed_passphrase)
|
||||||
|
.bind(user.id)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
if row.rows_affected() > 0 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(sqlx::Error::RowNotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
service_user: &textsender_models::user::ServiceUser,
|
service_user: &textsender_models::user::ServiceUser,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub fn create_token(
|
|||||||
message: String::from(MESSAGE),
|
message: String::from(MESSAGE),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
user_id: *id,
|
||||||
};
|
};
|
||||||
textsender_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
textsender_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ pub fn create_service_token(
|
|||||||
message: String::from(SERVICE_SUBJECT),
|
message: String::from(SERVICE_SUBJECT),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
user_id: *id,
|
||||||
};
|
};
|
||||||
textsender_models::token::create_token(provided, &resource, time::Duration::hours(1))
|
textsender_models::token::create_token(provided, &resource, time::Duration::hours(1))
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ pub fn create_service_refresh_token(
|
|||||||
message: String::from(SERVICE_SUBJECT),
|
message: String::from(SERVICE_SUBJECT),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
user_id: *id,
|
||||||
};
|
};
|
||||||
textsender_models::token::create_token(key, &resource, time::Duration::hours(4))
|
textsender_models::token::create_token(key, &resource, time::Duration::hours(4))
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ pub fn verify_token(key: &String, token: &String) -> bool {
|
|||||||
|
|
||||||
pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> {
|
pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> {
|
||||||
match get_payload(key, token) {
|
match get_payload(key, token) {
|
||||||
Ok((payload, _header)) => match payload.claim("id") {
|
Ok((payload, _header)) => match payload.claim("user_id") {
|
||||||
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
||||||
Ok(extracted) => Ok(extracted),
|
Ok(extracted) => Ok(extracted),
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
|||||||
+509
-18
@@ -134,6 +134,7 @@ pub mod requests {
|
|||||||
app.clone().oneshot(req).await
|
app.clone().oneshot(req).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Function to call service user login endpoint
|
||||||
pub async fn login_service_user(
|
pub async fn login_service_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
username: &str,
|
username: &str,
|
||||||
@@ -152,6 +153,78 @@ pub mod requests {
|
|||||||
|
|
||||||
app.clone().oneshot(req).await
|
app.clone().oneshot(req).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Function to call token refresh endpoint
|
||||||
|
pub async fn refresh_token(
|
||||||
|
app: &axum::Router,
|
||||||
|
access_token: &str,
|
||||||
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"access_token": access_token,
|
||||||
|
});
|
||||||
|
let req = axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::POST)
|
||||||
|
.uri(super::callers::endpoints::REFRESH_TOKEN)
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||||
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
app.clone().oneshot(req).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Function to call update password endpoint
|
||||||
|
pub async fn update_password(
|
||||||
|
app: &axum::Router,
|
||||||
|
user_id: &uuid::Uuid,
|
||||||
|
current_password: &str,
|
||||||
|
updated_password: &str,
|
||||||
|
confirmed_password: &str,
|
||||||
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"user_id": user_id,
|
||||||
|
"current_password": current_password,
|
||||||
|
"updated_password": updated_password,
|
||||||
|
"confirmed_password": confirmed_password,
|
||||||
|
});
|
||||||
|
match axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::PATCH)
|
||||||
|
.uri(super::callers::endpoints::UPDATE_PASSWORD)
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||||
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
|
{
|
||||||
|
Ok(req) => match app.clone().oneshot(req).await {
|
||||||
|
Ok(resp) => Ok(resp),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Function to call update name of user endpoint
|
||||||
|
pub async fn update_name_of_user(
|
||||||
|
app: &axum::Router,
|
||||||
|
user_id: &uuid::Uuid,
|
||||||
|
firstname: &str,
|
||||||
|
lastname: &str,
|
||||||
|
) -> Result<axum::response::Response, axum::http::Error> {
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"user_id": user_id,
|
||||||
|
"firstname": firstname,
|
||||||
|
"lastname": lastname,
|
||||||
|
});
|
||||||
|
match axum::http::Request::builder()
|
||||||
|
.method(axum::http::Method::PATCH)
|
||||||
|
.uri(super::callers::endpoints::UPDATE_USER_NAME)
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||||
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
|
{
|
||||||
|
Ok(req) => match app.clone().oneshot(req).await {
|
||||||
|
Ok(resp) => Ok(resp),
|
||||||
|
Err(err) => Err(axum::http::Error::from(err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test user firstname
|
/// Test user firstname
|
||||||
@@ -164,26 +237,49 @@ const TEST_USERNAME: &str = "BillyBob01";
|
|||||||
const TEST_PASSWORD: &str = "923ndcry392qryudx328qrdy328r";
|
const TEST_PASSWORD: &str = "923ndcry392qryudx328qrdy328r";
|
||||||
/// Test user phone number
|
/// Test user phone number
|
||||||
const TEST_PHONE_NUMBER: &str = "+10123456789";
|
const TEST_PHONE_NUMBER: &str = "+10123456789";
|
||||||
|
/// Test updated user password
|
||||||
|
const TEST_UPDATED_PASSWORD: &str = "3cnf29ry8q27i3yrc928qi37ryndxc2198q7yd9xzq12837e";
|
||||||
|
|
||||||
|
/// Test updated user firstname
|
||||||
|
const TEST_UPDATED_FIRSTNAME: &str = "Kuoth";
|
||||||
|
/// Test updated user lastname
|
||||||
|
const TEST_UPDATED_LASTNAME: &str = "Wech";
|
||||||
|
|
||||||
/// Test service username
|
/// Test service username
|
||||||
const TEST_SERVICE_USERNAME: &str = "swoon";
|
const TEST_SERVICE_USERNAME: &str = "swoon";
|
||||||
/// Test service passphrase
|
/// Test service passphrase
|
||||||
const TEST_SERVICE_PASSPHRASE: &str = "4n5cf349tfy34w857ty39wq45nfdq23";
|
const TEST_SERVICE_PASSPHRASE: &str = "4n5cf349tfy34w857ty39wq45nfdq23";
|
||||||
|
/// Test updated service user passphrase
|
||||||
|
const TEST_SERVICE_UPDATED_PASSPHRASE: &str = "3487ncfyth934287fcrty32487fry32in7";
|
||||||
|
|
||||||
async fn convert_response<T>(response: axum::response::Response) -> Result<T, std::io::Error>
|
mod util {
|
||||||
|
pub async fn convert_response<T>(
|
||||||
|
response: axum::response::Response,
|
||||||
|
) -> Result<T, std::io::Error>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
match axum::body::to_bytes(response.into_body(), usize::MAX).await {
|
match axum::body::to_bytes(response.into_body(), usize::MAX).await {
|
||||||
Ok(body) => {
|
Ok(body) => {
|
||||||
let resp: T = serde_json::from_slice(&body).unwrap();
|
let resp: T = match serde_json::from_slice(&body) {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
Ok(resp)
|
Ok(resp)
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn register_user(
|
mod flow {
|
||||||
|
use super::callers;
|
||||||
|
use super::requests;
|
||||||
|
use super::util;
|
||||||
|
|
||||||
|
pub async fn register_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<textsender_models::user::User, std::io::Error> {
|
) -> Result<textsender_models::user::User, std::io::Error> {
|
||||||
match requests::register_user(&app).await {
|
match requests::register_user(&app).await {
|
||||||
@@ -194,7 +290,9 @@ async fn register_user(
|
|||||||
response.status()
|
response.status()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
match convert_response::<callers::register::response::Response>(response).await {
|
match util::convert_response::<callers::register::response::Response>(response)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if response.data.len() > 0 {
|
if response.data.len() > 0 {
|
||||||
let user = response.data[0].clone();
|
let user = response.data[0].clone();
|
||||||
@@ -211,7 +309,7 @@ async fn register_user(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login_user(
|
pub async fn login_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
username: &str,
|
username: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
@@ -224,7 +322,11 @@ async fn login_user(
|
|||||||
response.status()
|
response.status()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
match convert_response::<callers::login::response::LoginResponse>(response).await {
|
match util::convert_response::<callers::login::response::LoginResponse>(
|
||||||
|
response,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if response.data.len() > 0 {
|
if response.data.len() > 0 {
|
||||||
let user = response.data[0].clone();
|
let user = response.data[0].clone();
|
||||||
@@ -241,7 +343,7 @@ async fn login_user(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn register_service_user(
|
pub async fn register_service_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<textsender_models::user::ServiceUser, std::io::Error> {
|
) -> Result<textsender_models::user::ServiceUser, std::io::Error> {
|
||||||
match requests::register_service_user(&app).await {
|
match requests::register_service_user(&app).await {
|
||||||
@@ -252,9 +354,9 @@ async fn register_service_user(
|
|||||||
response.status()
|
response.status()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
match convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
match util::convert_response::<
|
||||||
response,
|
callers::register::response::RegisterServiceUserResponse,
|
||||||
)
|
>(response)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@@ -273,7 +375,7 @@ async fn register_service_user(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login_service_user(
|
pub async fn login_service_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
username: &str,
|
username: &str,
|
||||||
passphrase: &str,
|
passphrase: &str,
|
||||||
@@ -286,7 +388,7 @@ async fn login_service_user(
|
|||||||
response.status()
|
response.status()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
match convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
match util::convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
||||||
response,
|
response,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -307,6 +409,119 @@ async fn login_service_user(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn refresh_token(
|
||||||
|
app: &axum::Router,
|
||||||
|
access_token: &str,
|
||||||
|
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||||
|
match requests::refresh_token(app, access_token).await {
|
||||||
|
Ok(response) => {
|
||||||
|
if axum::http::StatusCode::OK != response.status() {
|
||||||
|
Err(std::io::Error::other(format!(
|
||||||
|
"Status code is off {:?}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
match util::convert_response::<callers::login::response::RefreshTokenResponse>(
|
||||||
|
response,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if response.data.len() > 0 {
|
||||||
|
let login_result = response.data[0].clone();
|
||||||
|
Ok(login_result)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_password(
|
||||||
|
app: &axum::Router,
|
||||||
|
user_id: &uuid::Uuid,
|
||||||
|
current_password: &str,
|
||||||
|
updated_password: &str,
|
||||||
|
confirmed_password: &str,
|
||||||
|
) -> Result<uuid::Uuid, std::io::Error> {
|
||||||
|
match requests::update_password(
|
||||||
|
app,
|
||||||
|
user_id,
|
||||||
|
current_password,
|
||||||
|
updated_password,
|
||||||
|
confirmed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if axum::http::StatusCode::OK != response.status() {
|
||||||
|
Err(std::io::Error::other(format!(
|
||||||
|
"Status code is off {:?}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
match util::convert_response::<callers::login::response::UpdatePasswordResponse>(
|
||||||
|
response,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if response.data.len() > 0 {
|
||||||
|
let id = response.data[0].clone();
|
||||||
|
Ok(id)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_name_of_user(
|
||||||
|
app: &axum::Router,
|
||||||
|
user_id: &uuid::Uuid,
|
||||||
|
firstname: &str,
|
||||||
|
lastname: &str,
|
||||||
|
) -> Result<textsender_models::user::User, std::io::Error> {
|
||||||
|
match requests::update_name_of_user(app, user_id, firstname, lastname).await {
|
||||||
|
Ok(response) => {
|
||||||
|
if axum::http::StatusCode::OK != response.status() {
|
||||||
|
Err(std::io::Error::other(format!(
|
||||||
|
"Status code is off {:?}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
match util::convert_response::<callers::login::response::UserUpdateNameResponse>(
|
||||||
|
response,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if response.data.len() > 0 {
|
||||||
|
let user = response.data[0].clone();
|
||||||
|
Ok(user)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_register_user() {
|
async fn test_register_user() {
|
||||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
@@ -327,7 +542,7 @@ async fn test_register_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_user(&app).await {
|
match flow::register_user(&app).await {
|
||||||
Ok(returned_user) => {
|
Ok(returned_user) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
TEST_USERNAME, returned_user.username,
|
TEST_USERNAME, returned_user.username,
|
||||||
@@ -367,8 +582,8 @@ async fn test_login_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_user(&app).await {
|
match flow::register_user(&app).await {
|
||||||
Ok(user) => match login_user(&app, &user.username, TEST_PASSWORD).await {
|
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
|
||||||
Ok(login_result) => {
|
Ok(login_result) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
@@ -415,7 +630,7 @@ async fn test_register_service_user() {
|
|||||||
|
|
||||||
match requests::register_service_user(&app).await {
|
match requests::register_service_user(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
match util::convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
||||||
response,
|
response,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -466,14 +681,16 @@ async fn test_login_service_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_service_user(&app).await {
|
match flow::register_service_user(&app).await {
|
||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
user.id.is_nil(),
|
user.id.is_nil(),
|
||||||
"The service user id should not be nil"
|
"The service user id should not be nil"
|
||||||
);
|
);
|
||||||
match login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE).await {
|
match flow::login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(login_result) => {
|
Ok(login_result) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
@@ -498,3 +715,277 @@ async fn test_login_service_user() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_refresh_token() {
|
||||||
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
|
let db_name = db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
match db_mgr::create_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Success");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
assert!(false, "Error: {:?}", e.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||||
|
|
||||||
|
db::init::migrations(&pool).await;
|
||||||
|
|
||||||
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
|
match flow::register_user(&app).await {
|
||||||
|
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
|
||||||
|
Ok(login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
login_result.access_token.is_empty(),
|
||||||
|
"Access token is empty when it should not be"
|
||||||
|
);
|
||||||
|
match flow::refresh_token(&app, &login_result.access_token).await {
|
||||||
|
Ok(refresh_login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
refresh_login_result.access_token.is_empty(),
|
||||||
|
"Refreshed access token should not be empty"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match flow::register_service_user(&app).await {
|
||||||
|
Ok(user) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
user.id.is_nil(),
|
||||||
|
"The service user id should not be nil"
|
||||||
|
);
|
||||||
|
match flow::login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
login_result.access_token.is_empty(),
|
||||||
|
"Access token is empty when it should not be"
|
||||||
|
);
|
||||||
|
|
||||||
|
match flow::refresh_token(&app, &login_result.access_token).await {
|
||||||
|
Ok(refresh_login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
refresh_login_result.access_token.is_empty(),
|
||||||
|
"Refreshed access token should not be empty"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match db_mgr::drop_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_update_password() {
|
||||||
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
|
let db_name = db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
match db_mgr::create_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Success");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
assert!(false, "Error: {:?}", e.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||||
|
|
||||||
|
db::init::migrations(&pool).await;
|
||||||
|
|
||||||
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
|
match flow::register_user(&app).await {
|
||||||
|
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
|
||||||
|
Ok(login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
login_result.access_token.is_empty(),
|
||||||
|
"Access token is empty when it should not be"
|
||||||
|
);
|
||||||
|
|
||||||
|
match flow::update_password(
|
||||||
|
&app,
|
||||||
|
&user.id,
|
||||||
|
TEST_PASSWORD,
|
||||||
|
TEST_UPDATED_PASSWORD,
|
||||||
|
TEST_UPDATED_PASSWORD,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(id) => {
|
||||||
|
assert_eq!(id, user.id, "Ids do not match");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match flow::register_service_user(&app).await {
|
||||||
|
Ok(service_user) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
service_user.id.is_nil(),
|
||||||
|
"The service user id should not be nil"
|
||||||
|
);
|
||||||
|
match flow::login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
login_result.access_token.is_empty(),
|
||||||
|
"Access token is empty when it should not be"
|
||||||
|
);
|
||||||
|
|
||||||
|
match flow::update_password(
|
||||||
|
&app,
|
||||||
|
&service_user.id,
|
||||||
|
TEST_SERVICE_PASSPHRASE,
|
||||||
|
TEST_SERVICE_UPDATED_PASSPHRASE,
|
||||||
|
TEST_SERVICE_UPDATED_PASSPHRASE,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(id) => {
|
||||||
|
assert_eq!(id, service_user.id, "Ids do not match");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match db_mgr::drop_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_update_name_of_password() {
|
||||||
|
let tm_pool = db_mgr::get_pool().await.unwrap();
|
||||||
|
let db_name = db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
match db_mgr::create_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Success");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
assert!(false, "Error: {:?}", e.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||||
|
|
||||||
|
db::init::migrations(&pool).await;
|
||||||
|
|
||||||
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
|
match flow::register_user(&app).await {
|
||||||
|
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
|
||||||
|
Ok(login_result) => {
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
login_result.access_token.is_empty(),
|
||||||
|
"Access token is empty when it should not be"
|
||||||
|
);
|
||||||
|
|
||||||
|
match flow::update_name_of_user(
|
||||||
|
&app,
|
||||||
|
&user.id,
|
||||||
|
TEST_UPDATED_FIRSTNAME,
|
||||||
|
TEST_UPDATED_LASTNAME,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(user) => {
|
||||||
|
assert_eq!(
|
||||||
|
TEST_UPDATED_FIRSTNAME, user.firstname,
|
||||||
|
"Firstname do not match"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
TEST_UPDATED_LASTNAME, user.lastname,
|
||||||
|
"Lastname do not match"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match db_mgr::drop_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user