-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: add attestation middleware #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: add attestation middleware #506
Conversation
7d8ebcb to
490fe8f
Compare
490fe8f to
4db0df2
Compare
Pull Request Test Coverage Report for Build 12013926275Details
💛 - Coveralls |
Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
91130fd to
36de277
Compare
anirudh2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good! Just fix the docstring!
| attestation: Option<Attestation>, | ||
| } | ||
|
|
||
| /// Check if the query can be attestable generates attestation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be attestable generates attestation
This is worded strangely. I think you meant to say "is attestable?"
| let app = Router::new().route("/", get(handle)).layer(middleware); | ||
|
|
||
| // with signer | ||
| let res = app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use this same code three times in a row in the 3 tests in this file, I suggest you do the change below. Should economize a few lines.
// add helper send_request function
async fn send_test_request(app: &Router, signer: Option<AttestationSigner>) -> Response<Body> {
let mut request = Request::builder().uri("/").body(Body::empty()).unwrap();
if let Some(s) = signer {
request.extensions_mut().insert(s);
}
app.clone().oneshot(request).await.unwrap()
}
//then substitute according in the tests:
#[tokio::test]
async fn test_create_attestation() {
let (allocation, signer) = allocation_signer();
let middleware = from_fn(attestation_middleware);
let handle = move |_: Request<Body>| async move {
let mut res = Response::new(RESPONSE.to_string());
res.extensions_mut().insert(AttestationInput::Attestable {
req: REQUEST.to_string(),
});
res
};
let app = Router::new().route("/", get(handle)).layer(middleware);
// Use helper function to send request
let res = send_test_request(&app, Some(signer.clone())).await;
assert_eq!(res.status(), StatusCode::OK);
let response = payload_from_response(res).await;
assert_eq!(response.graphql_response, RESPONSE.to_string());
let attestation = response.attestation.unwrap();
assert!(signer
.verify(&attestation, REQUEST, RESPONSE, &allocation.id)
.is_ok());
}
#[tokio::test]
async fn test_non_assignable() {
let (_, signer) = allocation_signer();
let handle = move |_: Request<Body>| async move { Response::new(RESPONSE.to_string()) };
let middleware = from_fn(attestation_middleware);
let app = Router::new().route("/", get(handle)).layer(middleware);
// Use helper function to send request
let res = send_test_request(&app, Some(signer.clone())).await;
assert_eq!(res.status(), StatusCode::OK);
let response = payload_from_response(res).await;
assert_eq!(response.graphql_response, RESPONSE.to_string());
assert!(response.attestation.is_none());
}
#[tokio::test]
async fn test_no_signer() {
let handle = move |_: Request<Body>| async move { Response::new(RESPONSE.to_string()) };
let middleware = from_fn(attestation_middleware);
let app = Router::new().route("/", get(handle)).layer(middleware);
// Use helper function to send request without signer
let res = send_test_request(&app, None).await;
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
}Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
Signed-off-by: Gustavo Inacio <[email protected]>
anirudh2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good from my side. Once Pedro is good, feel free to merge!
Signed-off-by: Gustavo Inacio [email protected]Signed-off-by: Gustavo Inacio [email protected]