Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ workflows:
- main
- toolkit/required_builds:
min_rust_version: << pipeline.parameters.min-rust-version >>
cargo_all_features: false
- toolkit/optional_builds:
min_rust_version: << pipeline.parameters.min-rust-version >>
cargo_all_features: false
- toolkit/common_tests:
min_rust_version: << pipeline.parameters.min-rust-version >>
cargo_all_features: false
- toolkit/idiomatic_rust:
min_rust_version: << pipeline.parameters.min-rust-version >>
- toolkit/security:
Expand All @@ -98,11 +101,13 @@ workflows:
parameters:
features:
[
"-F hcaptcha,ext,rustls-backend",
"-F hcaptcha,ext,rustls-backend,enterprise",
"",
"-F hcaptcha,rustls-backend",
"-F hcaptcha,ext,rustls-backend,trace,enterprise",
"-F hcaptcha,nativetls-backend",
"-F hcaptcha,rustls-backend,enterprise",
"",
"-F hcaptcha,rustls-backend,trace,enterprise",
"-F recaptcha,rustls-backend",
"-F recaptcha,nativetls-backend",
]
requires:
- toolkit/common_tests
Expand Down
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"sonarlint.connectedMode.project": {
"connectionId": "jerus-org",
"projectKey": "jerus-org_captval"
}
},
"rust-analyzer.check.features": [
"hcaptcha"
],
"rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.cargo.features": [
"hcaptcha"
],
"rust-analyzer.check.noDefaultFeatures": true
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ♻️ refactor(response)-streamline response formatting(pr [#73])
- ♻️ refactor(captcha)-rename ClientResponse to Token(pr [#74])
- ♻️ refactor(hcaptcha)-rename client_response to token module(pr [#75])
- 🔧 chore(cargo)-add recaptcha support to captval(pr [#76])

### Fixed

Expand Down Expand Up @@ -178,6 +179,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#73]: https://github.com/jerus-org/captval/pull/73
[#74]: https://github.com/jerus-org/captval/pull/74
[#75]: https://github.com/jerus-org/captval/pull/75
[#76]: https://github.com/jerus-org/captval/pull/76
[Unreleased]: https://github.com/jerus-org/captval/compare/v0.1.2...HEAD
[0.1.2]: https://github.com/jerus-org/captval/compare/v0.1.0...v0.1.2
[0.1.0]: https://github.com/jerus-org/captval/releases/tag/v0.1.0
5 changes: 5 additions & 0 deletions crates/captval/.vscodepqor/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.cargo.features": [
"hcaptcha"
]
}
15 changes: 11 additions & 4 deletions crates/captval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ authors = ["Jeremiah Russell <[email protected]>"]
license = "MIT OR Apache-2.0"
readme = "README.md"
categories = ["web-programming"]
keywords = ["hcaptcha", "captcha", "security", "backend", "protection"]
keywords = [
"hcaptcha",
"recaptcha",
"captcha",
"security",
"backend",
"protection",
]
include = [
"**/*.rs",
"Cargo.toml",
Expand All @@ -24,7 +31,6 @@ publish = true

[dependencies]
captval_derive = { version = "0.1.2", path = "../captval_derive" }
hex = { workspace = true, optional = true }
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -38,6 +44,7 @@ uuid.workspace = true
chrono.workspace = true
claims.workspace = true
env_logger.workspace = true
hex.workspace = true
itertools.workspace = true
lambda_runtime.workspace = true
mockd = { workspace = true }
Expand All @@ -53,10 +60,10 @@ trybuild.workspace = true
wiremock.workspace = true

[features]
default = ["hcaptcha", "ext", "rustls-backend"]
default = ["hcaptcha", "rustls-backend"]
enterprise = []
ext = ["dep:hex"]
hcaptcha = []
recaptcha = []
nativetls-backend = ["reqwest/native-tls"]
nightly = []
rustls-backend = ["reqwest/rustls-tls"]
Expand Down
25 changes: 19 additions & 6 deletions crates/captval/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,36 @@
// const RESET: &str = "\u{001b}[0m";

use crate::Error;
use crate::Form;
use crate::Request;
use crate::Response;
use reqwest::Url;
// #[cfg(target_arch = "wasm32")]
// use tokio::runtime;

mod form;

use form::Form;
/// Returns the default verification URL based on enabled features
fn default_verify_url() -> &'static str {
#[cfg(feature = "hcaptcha")]
{
crate::hcaptcha::VERIFY_URL
}
#[cfg(all(feature = "recaptcha", not(feature = "hcaptcha")))]
{
crate::recaptcha::VERIFY_URL
}
#[cfg(not(any(feature = "hcaptcha", feature = "recaptcha")))]
{
compile_error!("At least one of 'hcaptcha' or 'recaptcha' features must be enabled")
}
}

/// Client to submit a request to a Captval validation endpoint.
#[cfg_attr(docsrs, allow(rustdoc::missing_doc_code_examples))]
#[derive(Debug)]
pub struct Client {
/// HTTP Client to submit request to endpoint and read the response.
client: reqwest::Client,
/// Url for the endpoint.
/// Captcha endpoint to submit request to.
url: Url,
}

Expand Down Expand Up @@ -105,7 +118,7 @@ impl Client {
pub fn new() -> Client {
Client {
client: reqwest::Client::new(),
url: Url::parse(crate::VERIFY_URL).expect("API url string corrupt"),
url: Url::parse(default_verify_url()).expect("API url string corrupt"),
}
}

Expand Down Expand Up @@ -555,7 +568,7 @@ mod tests {
let client = Client::default();
// Here we would check the side effect or state change
// For example, if new() sets a specific field, we would assert that field's value
let expected_value = Url::parse(crate::VERIFY_URL).unwrap();
let expected_value = Url::parse(default_verify_url()).unwrap();
assert!(client.url == expected_value);
}

Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions crates/captval/src/hcaptcha.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
mod code;
#[cfg(not(feature = "ext"))]
#[doc(hidden)]
mod secret;
#[cfg(feature = "ext")]
#[doc(hidden)]
mod secret_ext;
#[doc(hidden)]
mod sitekey;
#[doc(hidden)]
mod token;

// pub(crate) use client_response::ClientResponse;
pub use code::Code;

#[cfg(not(feature = "ext"))]
pub(crate) use secret::Secret;
#[allow(unused_imports)]
#[cfg(feature = "ext")]
pub(crate) use secret_ext::Secret;
#[allow(unused_imports)]
pub(crate) use sitekey::Sitekey;
pub use token::Token;

/// Endpoint url for the Hcaptcha siteverify API.
pub const VERIFY_URL: &str = "https://api.hcaptcha.com/siteverify";
186 changes: 0 additions & 186 deletions crates/captval/src/hcaptcha/secret_ext.rs

This file was deleted.

Loading