Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 5e680ec

Browse files
tomusdrw5chdn
authored andcommitted
Remove initial token for WS. (#9545)
1 parent decfe81 commit 5e680ec

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed

rpc/src/authcodes.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ impl TimeProvider for DefaultTimeProvider {
5050
const TIME_THRESHOLD: u64 = 7;
5151
/// minimal length of hash
5252
const TOKEN_LENGTH: usize = 16;
53-
/// special "initial" token used for authorization when there are no tokens yet.
54-
const INITIAL_TOKEN: &'static str = "initial";
5553
/// Separator between fields in serialized tokens file.
5654
const SEPARATOR: &'static str = ";";
5755
/// Number of seconds to keep unused tokens.
@@ -163,16 +161,6 @@ impl<T: TimeProvider> AuthCodes<T> {
163161

164162
let as_token = |code| keccak(format!("{}:{}", code, time));
165163

166-
// Check if it's the initial token.
167-
if self.is_empty() {
168-
let initial = &as_token(INITIAL_TOKEN) == hash;
169-
// Initial token can be used only once.
170-
if initial {
171-
let _ = self.generate_new();
172-
}
173-
return initial;
174-
}
175-
176164
// look for code
177165
for code in &mut self.codes {
178166
if &as_token(&code.code) == hash {
@@ -239,7 +227,7 @@ mod tests {
239227
}
240228

241229
#[test]
242-
fn should_return_true_if_code_is_initial_and_store_is_empty() {
230+
fn should_return_false_even_if_code_is_initial_and_store_is_empty() {
243231
// given
244232
let code = "initial";
245233
let time = 99;
@@ -250,7 +238,7 @@ mod tests {
250238
let res2 = codes.is_valid(&generate_hash(code, time), time);
251239

252240
// then
253-
assert_eq!(res1, true);
241+
assert_eq!(res1, false);
254242
assert_eq!(res2, false);
255243
}
256244

rpc/src/tests/ws.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod testing {
136136
}
137137

138138
#[test]
139-
fn should_allow_initial_connection_but_only_once() {
139+
fn should_not_allow_initial_connection_even_once() {
140140
// given
141141
let (server, port, authcodes) = serve();
142142
let code = "initial";
@@ -160,26 +160,9 @@ mod testing {
160160
timestamp,
161161
)
162162
);
163-
let response2 = http_client::request(server.addr(),
164-
&format!("\
165-
GET / HTTP/1.1\r\n\
166-
Host: 127.0.0.1:{}\r\n\
167-
Connection: Close\r\n\
168-
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n\
169-
Sec-WebSocket-Protocol:{:?}_{}\r\n\
170-
Sec-WebSocket-Version: 13\r\n\
171-
\r\n\
172-
{{}}
173-
",
174-
port,
175-
keccak(format!("{}:{}", code, timestamp)),
176-
timestamp,
177-
)
178-
);
179163

180164
// then
181-
assert_eq!(response1.status, "HTTP/1.1 101 Switching Protocols".to_owned());
182-
assert_eq!(response2.status, "HTTP/1.1 403 Forbidden".to_owned());
183-
http_client::assert_security_headers_present(&response2.headers, None);
165+
assert_eq!(response1.status, "HTTP/1.1 403 Forbidden".to_owned());
166+
http_client::assert_security_headers_present(&response1.headers, None);
184167
}
185168
}

0 commit comments

Comments
 (0)