@@ -6,13 +6,13 @@ use crate::{
6
6
revocation:: { Revocation , RevocationMessage } ,
7
7
Error , QuoteData , Result ,
8
8
} ;
9
- use actix_web:: { web, HttpRequest , HttpResponse , Responder } ;
9
+ use actix_web:: { http , web, HttpRequest , HttpResponse , Responder } ;
10
10
use log:: * ;
11
11
use serde:: { Deserialize , Serialize } ;
12
12
use std:: path:: { Path , PathBuf } ;
13
13
14
14
// This is Revocation request from the cloud verifier via REST API
15
- pub ( crate ) async fn revocation (
15
+ async fn revocation (
16
16
body : web:: Json < Revocation > ,
17
17
req : HttpRequest ,
18
18
data : web:: Data < QuoteData > ,
@@ -35,16 +35,97 @@ pub(crate) async fn revocation(
35
35
}
36
36
}
37
37
38
+ async fn notifications_default ( req : HttpRequest ) -> impl Responder {
39
+ let error;
40
+ let response;
41
+ let message;
42
+
43
+ match req. head ( ) . method {
44
+ http:: Method :: POST => {
45
+ error = 400 ;
46
+ message = "URI not supported, only /revocation is supported for POST in /notifications/ interface" ;
47
+ response = HttpResponse :: BadRequest ( )
48
+ . json ( JsonWrapper :: error ( error, message) ) ;
49
+ }
50
+ _ => {
51
+ error = 405 ;
52
+ message = "Method is not supported in /notifications/ interface" ;
53
+ response = HttpResponse :: MethodNotAllowed ( )
54
+ . insert_header ( http:: header:: Allow ( vec ! [ http:: Method :: POST ] ) )
55
+ . json ( JsonWrapper :: error ( error, message) ) ;
56
+ }
57
+ } ;
58
+
59
+ warn ! (
60
+ "{} returning {} response. {}" ,
61
+ req. head( ) . method,
62
+ error,
63
+ message
64
+ ) ;
65
+
66
+ response
67
+ }
68
+
69
+ /// Configure the endpoints for the /notifications scope
70
+ pub ( crate ) fn configure_notifications_endpoints (
71
+ cfg : & mut web:: ServiceConfig ,
72
+ ) {
73
+ _ = cfg
74
+ . service (
75
+ web:: resource ( "/revocation" ) . route ( web:: post ( ) . to ( revocation) ) ,
76
+ )
77
+ . default_service ( web:: to ( notifications_default) ) ;
78
+ }
79
+
38
80
#[ cfg( test) ]
39
81
mod tests {
40
82
use super :: * ;
41
83
use crate :: common:: API_VERSION ;
42
84
use actix_rt:: Arbiter ;
43
85
use actix_web:: { test, web, App } ;
44
- use serde_json:: json;
86
+ use serde_json:: { json, Value } ;
45
87
use std:: { fs, path:: Path } ;
46
88
use tokio:: sync:: mpsc;
47
89
90
+ #[ actix_rt:: test]
91
+ async fn test_notifications_default ( ) {
92
+ let mut app = test:: init_service (
93
+ App :: new ( ) . service ( web:: resource ( "/" ) . to ( notifications_default) ) ,
94
+ )
95
+ . await ;
96
+
97
+ let req = test:: TestRequest :: post ( )
98
+ . uri ( "/" )
99
+ . data ( "some data" )
100
+ . to_request ( ) ;
101
+
102
+ let resp = test:: call_service ( & app, req) . await ;
103
+ assert ! ( resp. status( ) . is_client_error( ) ) ;
104
+
105
+ let result: JsonWrapper < Value > = test:: read_body_json ( resp) . await ;
106
+
107
+ assert_eq ! ( result. results, json!( { } ) ) ;
108
+ assert_eq ! ( result. code, 400 ) ;
109
+
110
+ let req = test:: TestRequest :: delete ( ) . uri ( "/" ) . to_request ( ) ;
111
+
112
+ let resp = test:: call_service ( & app, req) . await ;
113
+ assert ! ( resp. status( ) . is_client_error( ) ) ;
114
+
115
+ let headers = resp. headers ( ) ;
116
+
117
+ assert ! ( headers. contains_key( "allow" ) ) ;
118
+ assert_eq ! (
119
+ headers. get( "allow" ) . unwrap( ) . to_str( ) . unwrap( ) , //#[allow_ci]
120
+ "POST"
121
+ ) ;
122
+
123
+ let result: JsonWrapper < Value > = test:: read_body_json ( resp) . await ;
124
+
125
+ assert_eq ! ( result. results, json!( { } ) ) ;
126
+ assert_eq ! ( result. code, 405 ) ;
127
+ }
128
+
48
129
#[ cfg( feature = "testing" ) ]
49
130
#[ actix_rt:: test]
50
131
async fn test_revocation ( ) {
0 commit comments