• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-edge / #1444

21 Jan 2025 08:37AM UTC coverage: 19.689% (-53.4%) from 73.06%
#1444

push

web-flow
dep-update: bump serde_json from 1.0.135 to 1.0.137 (#678)

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.135 to 1.0.137.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.135...v1.0.137)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

405 of 2057 relevant lines covered (19.69%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.95
/server/src/middleware/validate_token.rs
1
use crate::auth::token_validator::TokenValidator;
2
use crate::types::{EdgeToken, TokenType, TokenValidationStatus};
3
use actix_web::{
4
    body::MessageBody,
5
    dev::{ServiceRequest, ServiceResponse},
6
    web::Data,
7
    HttpResponse,
8
};
9
use dashmap::DashMap;
10

11
pub async fn validate_token(
1✔
12
    token: EdgeToken,
13
    req: ServiceRequest,
14
    srv: crate::middleware::as_async_middleware::Next<impl MessageBody + 'static>,
15
) -> Result<ServiceResponse<impl MessageBody>, actix_web::Error> {
16
    let maybe_validator = req.app_data::<Data<TokenValidator>>();
2✔
17
    let token_cache = req
2✔
18
        .app_data::<Data<DashMap<String, EdgeToken>>>()
19
        .unwrap()
20
        .clone()
21
        .into_inner();
22
    match maybe_validator {
1✔
23
        Some(validator) => {
1✔
24
            let known_token = validator.register_token(token.token.clone()).await?;
2✔
25
            let res = match known_token.status {
1✔
26
                TokenValidationStatus::Validated => match known_token.token_type {
2✔
27
                    Some(TokenType::Frontend) => {
28
                        if req.path().contains("/api/frontend") || req.path().contains("/api/proxy")
×
29
                        {
30
                            srv.call(req).await?.map_into_left_body()
×
31
                        } else {
32
                            req.into_response(HttpResponse::Forbidden().finish())
×
33
                                .map_into_right_body()
34
                        }
35
                    }
36
                    Some(TokenType::Client) => {
37
                        if req.path().contains("/api/client") {
2✔
38
                            srv.call(req).await?.map_into_left_body()
3✔
39
                        } else {
40
                            req.into_response(HttpResponse::Forbidden().finish())
×
41
                                .map_into_right_body()
42
                        }
43
                    }
44
                    _ => req
×
45
                        .into_response(HttpResponse::Forbidden().finish())
×
46
                        .map_into_right_body(),
47
                },
48
                TokenValidationStatus::Unknown => req
×
49
                    .into_response(HttpResponse::Unauthorized().finish())
×
50
                    .map_into_right_body(),
51
                TokenValidationStatus::Invalid => req
×
52
                    .into_response(HttpResponse::Forbidden().finish())
×
53
                    .map_into_right_body(),
54
            };
55
            Ok(res)
1✔
56
        }
57
        None => {
58
            let res = match token_cache.get(&token.token) {
×
59
                Some(t) => {
×
60
                    let token = t.value();
×
61
                    match token.token_type {
×
62
                        Some(TokenType::Client) => {
63
                            if req.path().contains("/api/client") {
×
64
                                srv.call(req).await?.map_into_left_body()
×
65
                            } else {
66
                                req.into_response(HttpResponse::Forbidden().finish())
×
67
                                    .map_into_right_body()
68
                            }
69
                        }
70
                        Some(TokenType::Frontend) => {
71
                            if req.path().contains("/api/frontend")
×
72
                                || req.path().contains("/api/proxy")
×
73
                            {
74
                                srv.call(req).await?.map_into_left_body()
×
75
                            } else {
76
                                req.into_response(HttpResponse::Forbidden().finish())
×
77
                                    .map_into_right_body()
78
                            }
79
                        }
80
                        None => srv.call(req).await?.map_into_left_body(),
×
81
                        _ => req
×
82
                            .into_response(HttpResponse::Forbidden().finish())
×
83
                            .map_into_right_body(),
84
                    }
85
                }
86
                None => req
×
87
                    .into_response(HttpResponse::Forbidden().finish())
×
88
                    .map_into_right_body(),
89
            };
90

91
            Ok(res)
×
92
        }
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc