Merge branch 'testing' into messaging
This commit is contained in:
commit
a00dd2b442
19
.gitlab-ci.yml
Normal file
19
.gitlab-ci.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
image: rustlang/rust:nightly
|
||||||
|
|
||||||
|
basic-build:
|
||||||
|
stage: build
|
||||||
|
only:
|
||||||
|
- testing
|
||||||
|
script:
|
||||||
|
- cd server/
|
||||||
|
- cargo build --release
|
||||||
|
|
||||||
|
|
||||||
|
basic-test:
|
||||||
|
stage: test
|
||||||
|
only:
|
||||||
|
- testing
|
||||||
|
script:
|
||||||
|
- cargo run --release
|
||||||
|
- fc_id=$!
|
||||||
|
- bash ./tests/main.sh body
|
@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS `messages`(
|
|||||||
`time` BIGINT NOT NULL,
|
`time` BIGINT NOT NULL,
|
||||||
`content` VARCHAR(2048) NOT NULL,
|
`content` VARCHAR(2048) NOT NULL,
|
||||||
`author_id` BIGINT UNSIGNED NOT NULL,
|
`author_id` BIGINT UNSIGNED NOT NULL,
|
||||||
`channel_id` BIGINT UNSIGNED NOT NULL,
|
`channel_name` VARCHAR(255) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
FOREIGN KEY (`author_id`) REFERENCES members(`id`),
|
FOREIGN KEY (`author_id`) REFERENCES members(`id`),
|
||||||
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)
|
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)
|
||||||
|
@ -14,7 +14,8 @@ pub enum AuthReason {
|
|||||||
fn open_route(path: &str) -> bool {
|
fn open_route(path: &str) -> bool {
|
||||||
return path == routes::INVITE_JOIN
|
return path == routes::INVITE_JOIN
|
||||||
}
|
}
|
||||||
pub async fn wall_entry(path: &str, pool: &Pool, params: &serde_json::Value) -> Result<AuthReason, mysql_async::error::Error> {
|
pub async fn wall_entry(path: &str, pool: &Pool, params: &mut serde_json::Value) -> Result<AuthReason, mysql_async::error::Error> {
|
||||||
|
use serde_json::json;
|
||||||
// Start by Checking if the api key is in our keystore
|
// Start by Checking if the api key is in our keystore
|
||||||
if open_route(path) {
|
if open_route(path) {
|
||||||
Ok(AuthReason::OpenAuth)
|
Ok(AuthReason::OpenAuth)
|
||||||
@ -32,7 +33,11 @@ pub async fn wall_entry(path: &str, pool: &Pool, params: &serde_json::Value) ->
|
|||||||
match db_result {
|
match db_result {
|
||||||
Ok((_, row)) => {
|
Ok((_, row)) => {
|
||||||
match row{
|
match row{
|
||||||
Some(_) => Ok(AuthReason::Good),
|
Some(user_row) => {
|
||||||
|
params["userid"] = json!(user_row.0);
|
||||||
|
params["username"] = json!(user_row.1);
|
||||||
|
Ok(AuthReason::Good)
|
||||||
|
},
|
||||||
None => Ok(AuthReason::NoKey)
|
None => Ok(AuthReason::NoKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,9 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
|
|||||||
|
|
||||||
let params_res = http_params::parse_params(&mut body).await;
|
let params_res = http_params::parse_params(&mut body).await;
|
||||||
|
|
||||||
if let Ok(params) = params_res {
|
if let Ok(mut params) = params_res {
|
||||||
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
||||||
if let Ok(auth_result) = auth::wall_entry(path, &pool, ¶ms).await {
|
if let Ok(auth_result) = auth::wall_entry(path, &pool, &mut params).await {
|
||||||
// Deal with permissions errors at this point
|
// Deal with permissions errors at this point
|
||||||
match auth_result {
|
match auth_result {
|
||||||
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
||||||
@ -110,18 +110,42 @@ async fn shutdown_signal() {
|
|||||||
.expect("Failed to capture ctrl-c signal");
|
.expect("Failed to capture ctrl-c signal");
|
||||||
}
|
}
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() -> Result<(), u16>{
|
||||||
dotenv().ok();
|
const NO_ERR: u16 = 0;
|
||||||
|
const CONFIG_ERR: u16 = 1;
|
||||||
|
const SHUTDOWN_ERR: u16 = 2;
|
||||||
|
|
||||||
|
let mut main_ret: u16 = 0;
|
||||||
|
// setting up environment variables
|
||||||
|
let d_result = dotenv();
|
||||||
|
if let Err(_d) = d_result {
|
||||||
|
// we may be on a pipeline/prod environment so .env may not be there
|
||||||
|
if let Err(_e) = env::var("DATABASE_URL") {
|
||||||
|
main_ret |= CONFIG_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if main_ret == NO_ERR {
|
||||||
println!("Servering on localhost:8888");
|
println!("Servering on localhost:8888");
|
||||||
let addr = SocketAddr::from(([127,0,0,1], 8888));
|
let addr = SocketAddr::from(([127,0,0,1], 8888));
|
||||||
|
|
||||||
let service = make_service_fn(|_conn| async {
|
let service = make_service_fn(|_conn| async {
|
||||||
Ok::<_, Infallible>(service_fn(main_responder))
|
Ok::<_, Infallible>(service_fn(main_responder))
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = Server::bind(&addr).serve(service);
|
let server = Server::bind(&addr).serve(service);
|
||||||
let graceful_shutdown = server.with_graceful_shutdown(shutdown_signal());
|
let graceful_shutdown = server.with_graceful_shutdown(shutdown_signal());
|
||||||
|
|
||||||
if let Err(e) = graceful_shutdown.await {
|
if let Err(e) = graceful_shutdown.await {
|
||||||
|
main_ret |= SHUTDOWN_ERR;
|
||||||
eprintln!("Server shutdown error: {}", e);
|
eprintln!("Server shutdown error: {}", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if main_ret != 0 {
|
||||||
|
// dumb as heck loggin method here
|
||||||
|
if main_ret & CONFIG_ERR != 0 {println!("ERROR: Config was not setup properly => Missing {{DATABASE_URL}}");}
|
||||||
|
if main_ret & SHUTDOWN_ERR != 0 {println!("ERROR: Couldn't shutdown gracefully");}
|
||||||
|
Err(main_ret)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,21 +7,12 @@ use hyper::{Response, Body, StatusCode};
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
||||||
use crate::db_types::{UBigInt, VarChar};
|
use crate::db_types::{UBigInt};
|
||||||
|
|
||||||
|
|
||||||
struct Message {
|
pub async fn insert_message_table(pool: &Pool, content: &Value, channel_name: &Value, author_id: UBigInt)
|
||||||
id: UBigInt,
|
|
||||||
content: Option<VarChar>, // some messages later might only have file attachments and not text content
|
|
||||||
author_id: UBigInt,
|
|
||||||
channel_id: UBigInt,
|
|
||||||
permissions: UBigInt,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn insert_message_table(pool: &Pool, content: &Value, channel_id: &Value, author_id: UBigInt)
|
|
||||||
-> Result<(), Error>{
|
-> Result<(), Error>{
|
||||||
match (content.as_str(), channel_id.as_u64()) {
|
match (content.as_str(), channel_name.as_str()) {
|
||||||
(Some(content), Some(channel)) => {
|
(Some(content), Some(channel)) => {
|
||||||
let conn = pool.get_conn().await?;
|
let conn = pool.get_conn().await?;
|
||||||
let time = Utc::now().timestamp();
|
let time = Utc::now().timestamp();
|
||||||
|
@ -24,6 +24,18 @@ delete_channel() {
|
|||||||
log_result good_delete_channel 200 $code "$result"
|
log_result good_delete_channel 200 $code "$result"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_message() {
|
||||||
|
# creating a bs channel, we don't care about this operation
|
||||||
|
# as long as the other test passes this should be fine
|
||||||
|
$crl $POST $url/channel/create -d '{"secret":"secret","name":"msgchannel"}'
|
||||||
|
|
||||||
|
kv='{"secret":"secret", "content":"message sample", "channel":123}'
|
||||||
|
result=$($crl $POST $url/message/send -d "$kv")
|
||||||
|
code=$(echo "$result" | grep HTTP\/1.1 | awk '{print $2}')
|
||||||
|
# non-existant channel for now but whatever ignore for now
|
||||||
|
log_result good_send_message 200 $code "$result"
|
||||||
|
}
|
||||||
|
|
||||||
# Dispatcher to run our tests
|
# Dispatcher to run our tests
|
||||||
if [ -z $1 ];then
|
if [ -z $1 ];then
|
||||||
for cmd in $active_tests;do
|
for cmd in $active_tests;do
|
||||||
|
Loading…
Reference in New Issue
Block a user