Skip to content

Commit

Permalink
bug: add missing Tokenserver headers (#1243)
Browse files Browse the repository at this point in the history
Closes #1242
  • Loading branch information
ethowitz authored Mar 16, 2022
1 parent 291a40e commit 38de833
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/tokenserver/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ pub async fn get_tokenserver_result(
node_type: req.node_type,
};

Ok(HttpResponse::build(StatusCode::OK).json(result))
let timestamp = {
let start = SystemTime::now();
start.duration_since(UNIX_EPOCH).unwrap().as_secs()
};

// `X-Content-Type-Options: nosniff` was set automatically by the Pyramid cornice library
// on the Python Tokenserver. For the Rust Tokenserver, we set it in nginx instead of in the
// application code here.
Ok(HttpResponse::build(StatusCode::OK)
.header("X-Timestamp", timestamp.to_string())
.json(result))
}

fn get_token_plaintext(
Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/tokenserver/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,7 @@ def test_valid_request(self):
self.assertEqual(res.json['hashed_fxa_uid'],
self._fxa_metrics_hash(fxa_uid)[:32])
self.assertEqual(res.json['node_type'], 'spanner')
# The response should have an X-Timestamp header that contains the
# number of seconds since the UNIX epoch
self.assertIn('X-Timestamp', res.headers)
self.assertIsNotNone(int(res.headers['X-Timestamp']))

0 comments on commit 38de833

Please sign in to comment.