Skip to content

Commit

Permalink
bugfix header underscore handling for simplejwt #474
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Aug 2, 2021
1 parent c04c585 commit ea50846
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_security_definition(self, auto_schema):
else:
if header_name.startswith('HTTP_'):
header_name = header_name[5:]
header_name = header_name.capitalize()
header_name = header_name.replace('_', '-').capitalize()
return {
'type': 'apiKey',
'in': 'header',
Expand Down
14 changes: 14 additions & 0 deletions tests/contrib/test_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,17 @@ def test_simplejwt_non_bearer_keyword(no_warnings):
'description': 'Token-based authentication with required prefix "JWT"'
}
}


@pytest.mark.contrib('rest_framework_simplejwt')
@mock.patch('rest_framework_simplejwt.settings.api_settings.AUTH_HEADER_NAME', 'HTTP_X_TOKEN')
def test_simplejwt_non_std_header_name(no_warnings):
schema = generate_schema('/x', XViewset)
assert schema['components']['securitySchemes'] == {
'jwtAuth': {
'type': 'apiKey',
'in': 'header',
'name': 'X-token',
'description': 'Token-based authentication with required prefix "Bearer"'
}
}

0 comments on commit ea50846

Please sign in to comment.