@@ -57,8 +57,9 @@ impl SessionStore for MemoryStore {
57
57
async fn store_session ( & self , session : & mut Session ) -> Result < Option < String > , Self :: Error > {
58
58
log:: trace!( "storing session by id `{}`" , session. id( ) ) ;
59
59
session. reset_data_changed ( ) ;
60
+ let cookie_value = session. take_cookie_value ( ) ;
60
61
self . 0 . insert ( session. id ( ) . to_string ( ) , session. clone ( ) ) ;
61
- Ok ( session . take_cookie_value ( ) )
62
+ Ok ( cookie_value )
62
63
}
63
64
64
65
async fn destroy_session ( & self , session : & mut Session ) -> Result < ( ) , Self :: Error > {
@@ -116,7 +117,7 @@ mod tests {
116
117
session. insert ( "key" , "Hello" ) ?;
117
118
let cloned = session. clone ( ) ;
118
119
let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
119
- let loaded_session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
120
+ let loaded_session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
120
121
assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
121
122
assert_eq ! ( "Hello" , & loaded_session. get:: <String >( "key" ) . unwrap( ) ) ;
122
123
assert ! ( !loaded_session. is_expired( ) ) ;
@@ -132,11 +133,11 @@ mod tests {
132
133
session. insert ( "key" , "value" ) ?;
133
134
let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
134
135
135
- let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
136
+ let mut session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
136
137
session. insert ( "key" , "other value" ) ?;
137
138
138
139
assert_eq ! ( store. store_session( & mut session) . await ?, None ) ;
139
- let session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
140
+ let session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
140
141
assert_eq ! ( & mut session. get:: <String >( "key" ) . unwrap( ) , "other value" ) ;
141
142
142
143
Ok ( ( ) )
@@ -150,18 +151,18 @@ mod tests {
150
151
let original_expires = * session. expiry ( ) . unwrap ( ) ;
151
152
let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
152
153
153
- let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
154
+ let mut session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
154
155
155
156
assert_eq ! ( session. expiry( ) . unwrap( ) , & original_expires) ;
156
157
session. expire_in ( Duration :: from_secs ( 3 ) ) ;
157
158
let new_expires = * session. expiry ( ) . unwrap ( ) ;
158
159
assert_eq ! ( None , store. store_session( & mut session) . await ?) ;
159
160
160
- let session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
161
+ let session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
161
162
assert_eq ! ( session. expiry( ) . unwrap( ) , & new_expires) ;
162
163
163
164
task:: sleep ( Duration :: from_secs ( 3 ) ) . await ;
164
- assert_eq ! ( None , store. load_session( cookie_value) . await ?) ;
165
+ assert_eq ! ( None , store. load_session( & cookie_value) . await ?) ;
165
166
166
167
Ok ( ( ) )
167
168
}
@@ -176,14 +177,14 @@ mod tests {
176
177
177
178
let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
178
179
179
- let loaded_session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
180
+ let loaded_session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
180
181
assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
181
182
assert_eq ! ( "value" , & * loaded_session. get:: <String >( "key" ) . unwrap( ) ) ;
182
183
183
184
assert ! ( !loaded_session. is_expired( ) ) ;
184
185
185
186
task:: sleep ( Duration :: from_secs ( 3 ) ) . await ;
186
- assert_eq ! ( None , store. load_session( cookie_value) . await ?) ;
187
+ assert_eq ! ( None , store. load_session( & cookie_value) . await ?) ;
187
188
188
189
Ok ( ( ) )
189
190
}
@@ -197,9 +198,9 @@ mod tests {
197
198
198
199
let cookie = store. store_session ( & mut Session :: new ( ) ) . await ?. unwrap ( ) ;
199
200
assert_eq ! ( 4 , store. count( ) ) ;
200
- let mut session = store. load_session ( cookie. clone ( ) ) . await ?. unwrap ( ) ;
201
+ let mut session = store. load_session ( & cookie) . await ?. unwrap ( ) ;
201
202
store. destroy_session ( & mut session) . await ?;
202
- assert_eq ! ( None , store. load_session( cookie) . await ?) ;
203
+ assert_eq ! ( None , store. load_session( & cookie) . await ?) ;
203
204
assert_eq ! ( 3 , store. count( ) ) ;
204
205
205
206
// attempting to destroy the session again is not an error
0 commit comments