fix: update parameters to mCaptcha/mCaptcha

This commit is contained in:
Aravinth Manivannan 2023-10-19 09:55:00 +05:30
parent 786a9afe22
commit 3c445411e9
Signed by: realaravinth
GPG key ID: F8F50389936984FF
16 changed files with 307 additions and 6 deletions

View file

@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "SELECT\n public_id\n FROM\n survey_mcaptcha_campaign\n WHERE\n campaign_id = $1\n AND\n url_id = (SELECT ID FROM survey_mcaptcha_hostname WHERE secret = $2);",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "public_id",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false
]
},
"hash": "2904486838bed381aa00f6a1b1e9b860a74b07b15256f3764434901471ff820b"
}

View file

@ -0,0 +1,16 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO\n survey_mcaptcha_campaign (campaign_id, public_id, url_id)\n VALUES ($1, $2, (SELECT ID FROM survey_mcaptcha_hostname WHERE secret = $3));",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Varchar",
"Text"
]
},
"nullable": []
},
"hash": "38a517b011519ec80d35d12ea463e7aed1f25290a5f3e8b19c5aa781da362ae3"
}

View file

@ -0,0 +1,16 @@
{
"db_name": "PostgreSQL",
"query": "UPDATE\n survey_mcaptcha_campaign\n SET\n synced_till = $1\n WHERE \n campaign_id = $2\n AND\n url_id = (\n SELECT ID FROM survey_mcaptcha_hostname WHERE secret = $3\n )\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Text",
"Text"
]
},
"nullable": []
},
"hash": "3eb4799231e726cf566f81d6ec7bd30a5c75215dbc3179fae08a106388341c3f"
}

View file

@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS (SELECT 1 from survey_mcaptcha_hostname WHERE url = $1)",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "exists",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
null
]
},
"hash": "5c1ad3208ece06ba7a503d650e15d06906e56018798cba2b4672c393327131aa"
}

View file

@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT\n url\n FROM\n survey_mcaptcha_hostname\n WHERE\n secret = $1; ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "url",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false
]
},
"hash": "677376147c1346f9136c5d60914efc5062a25eb0ada991f04197189aa6dcb2c4"
}

View file

@ -0,0 +1,42 @@
{
"db_name": "PostgreSQL",
"query": "SELECT id, time, difficulty_factor, worker_type FROM survey_mcaptcha_analytics\n WHERE \n campaign_id = (\n SELECT \n ID FROM survey_mcaptcha_campaign \n WHERE \n public_id = $1\n )\n ORDER BY ID\n OFFSET $2 LIMIT $3\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "time",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "difficulty_factor",
"type_info": "Int4"
},
{
"ordinal": 3,
"name": "worker_type",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text",
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
false,
false
]
},
"hash": "714925a5209400a17bcafe23c34ce9546106e8bdd788c27ee579b278e671bcb0"
}

View file

@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS (\n SELECT\n url\n FROM\n survey_mcaptcha_hostname\n WHERE secret = $1\n )",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "exists",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
null
]
},
"hash": "7d764a7b1c2991dda7498f243c6e4bd83fdf431e3510f9afb0ef5e9b10f35181"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO survey_mcaptcha_hostname (url, secret) VALUES ($1, $2)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Varchar"
]
},
"nullable": []
},
"hash": "94205e3e65a8f6bf315a282ec8fcc64119dc08e5565925bb2a3f5fccf663b5ab"
}

View file

@ -0,0 +1,18 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO\n survey_mcaptcha_analytics (\n campaign_id, time, difficulty_factor, worker_type\n )\n VALUES ((\n SELECT\n ID\n FROM\n survey_mcaptcha_campaign\n WHERE \n campaign_id = $1\n AND\n url_id = (\n SELECT ID FROM survey_mcaptcha_hostname WHERE secret = $2\n )\n ), $3, $4, $5\n );",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text",
"Int4",
"Int4",
"Varchar"
]
},
"nullable": []
},
"hash": "997a3d0ce396d48a1804b6272124f0d8eed367916b28c240551b97aebcc9eb36"
}

View file

@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS (\n SELECT\n ID\n FROM\n survey_mcaptcha_campaign\n WHERE\n campaign_id = $1\n AND\n url_id = (\n SELECT\n ID\n FROM\n survey_mcaptcha_hostname\n WHERE\n secret = $2\n )\n )",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "exists",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
null
]
},
"hash": "9da39f618b9dea08360d4c1625650b5055de47a7e89f99ffc589b99d22b8ac9d"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "DELETE FROM survey_mcaptcha_hostname WHERE secret = $1 AND url =$2",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": []
},
"hash": "a3cddc0ace32cfb7df70e171b2618c7fe6d7824bbfcbae8248905e927049528b"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "UPDATE survey_mcaptcha_hostname set secret = $1 WHERE url = $2",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Text"
]
},
"nullable": []
},
"hash": "baabef729999fe63426b3b2373f1ecbf294d4bfddbce04209269644f4a7511ed"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "DELETE FROM\n survey_mcaptcha_campaign\n WHERE\n campaign_id = $1\n AND\n url_id = (\n SELECT\n ID\n FROM\n survey_mcaptcha_hostname\n WHERE\n secret = $2\n )",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": []
},
"hash": "dbe5d5c450a50bb829a39e6149eb4e6307547120b10762140d250f163b584a23"
}

View file

@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "SELECT\n synced_till\n FROM\n survey_mcaptcha_campaign\n WHERE \n campaign_id = $1\n AND\n url_id = (\n SELECT ID FROM survey_mcaptcha_hostname WHERE secret = $2\n );",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "synced_till",
"type_info": "Int4"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false
]
},
"hash": "f5c0480ed2829c3a3dbe7a8da2d95b43076b0dd18fe5137d7ba87bc8e56102fe"
}

View file

@ -33,6 +33,7 @@ pub fn services(cfg: &mut ServiceConfig) {
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct MCaptchaInstance {
pub url: Url,
pub auth_token: String,
}
#[actix_web_codegen_const_routes::post(path = "ROUTES.mcaptcha.register")]
@ -53,9 +54,9 @@ async fn register(
data.mcaptcha_register_instance(&url_str).await?
};
let secret = Secret { secret };
let payload = payload.into_inner();
data.mcaptcha
.share_secret(payload.into_inner().url, &secret)
.share_secret(payload.url, secret, payload.auth_token)
.await?;
Ok(HttpResponse::Ok())

View file

@ -47,7 +47,8 @@ pub trait MCaptchaClient:
async fn share_secret(
&self,
mut mcaptcha: Url,
secret: &Secret,
secret: String,
auth_token: String,
) -> ServiceResult<()>;
async fn download_benchmarks(
&self,
@ -101,12 +102,23 @@ impl MCaptchaClient for MCaptchaClientReqwest {
async fn share_secret(
&self,
mut mcaptcha: Url,
secret: &Secret,
secret: String,
auth_token: String,
) -> ServiceResult<()> {
#[derive(Serialize)]
struct S {
secret: String,
auth_token: String,
}
let msg = S {
secret,
auth_token,
};
mcaptcha.set_path("/api/v1/survey/secret");
self.client
.post(mcaptcha)
.json(secret)
.json(&msg)
.send()
.await
.unwrap();
@ -175,7 +187,8 @@ pub mod tests {
async fn share_secret(
&self,
mut mcaptcha: Url,
secret: &Secret,
secret: String,
auth_token: String,
) -> ServiceResult<()> {
mcaptcha.set_path("/api/v1/survey/secret");
let mut x = self.client.write().unwrap();