Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
de91ceaa
Commit
de91ceaa
authored
Jan 14, 2016
by
Syed Hassan Raza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix HTTP_USER_AGENT latin1 characters
parent
22e01a8c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
2 deletions
+22
-2
common/djangoapps/track/backends/tests/test_logger.py
+2
-0
common/djangoapps/track/middleware.py
+4
-0
common/djangoapps/track/tests/test_middleware.py
+14
-0
common/djangoapps/track/views/__init__.py
+1
-1
lms/djangoapps/instructor_task/api_helper.py
+1
-1
No files found.
common/djangoapps/track/backends/tests/test_logger.py
View file @
de91ceaa
# -*- coding: utf-8 -*-
"""Tests for Event tracker backend."""
from
__future__
import
absolute_import
import
json
...
...
common/djangoapps/track/middleware.py
View file @
de91ceaa
...
...
@@ -142,6 +142,10 @@ class TrackMiddleware(object):
for
header_name
,
context_key
in
META_KEY_TO_CONTEXT_KEY
.
iteritems
():
context
[
context_key
]
=
request
.
META
.
get
(
header_name
,
''
)
# HTTP_USER_AGENT user might can contain the information that include latin1 characters
# decoding this using latin1 scheme will prevent to raise UnicodeDecodeError when using
# json.dumps for tracking purpose.
context
[
'agent'
]
=
context
[
'agent'
]
.
decode
(
'latin1'
)
# Google Analytics uses the clientId to keep track of unique visitors. A GA cookie looks like
# this: _ga=GA1.2.1033501218.1368477899. The clientId is this part: 1033501218.1368477899.
google_analytics_cookie
=
request
.
COOKIES
.
get
(
'_ga'
)
...
...
common/djangoapps/track/tests/test_middleware.py
View file @
de91ceaa
# -*- coding: utf-8 -*-
"""Tests for tracking middleware."""
from
mock
import
patch
from
mock
import
sentinel
...
...
@@ -27,6 +29,18 @@ class TrackMiddlewareTestCase(TestCase):
self
.
track_middleware
.
process_request
(
request
)
self
.
assertTrue
(
self
.
mock_server_track
.
called
)
def
test_request_with_latin1_characters
(
self
):
"""
When HTTP_USER_AGENT in request.META contains latin1 characters.
"""
request
=
self
.
request_factory
.
get
(
'/somewhere'
)
request
.
META
[
'HTTP_USER_AGENT'
]
=
'test latin1
\xd3
\xe9
\xf1
'
# pylint: disable=no-member
context
=
self
.
get_context_for_request
(
request
)
# The bytes in the string on the right are utf8 encoded in the source file, so we decode them to construct
# a valid unicode string.
self
.
assertEqual
(
context
[
'agent'
],
'test latin1 Ó é ñ'
.
decode
(
'utf8'
))
def
test_default_filters_do_not_render_view
(
self
):
for
url
in
[
'/event'
,
'/event/1'
,
'/login'
,
'/heartbeat'
]:
request
=
self
.
request_factory
.
get
(
url
)
...
...
common/djangoapps/track/views/__init__.py
View file @
de91ceaa
...
...
@@ -105,7 +105,7 @@ def server_track(request, event_type, event, page=None):
"event_source"
:
"server"
,
"event_type"
:
event_type
,
"event"
:
event
,
"agent"
:
_get_request_header
(
request
,
'HTTP_USER_AGENT'
),
"agent"
:
_get_request_header
(
request
,
'HTTP_USER_AGENT'
)
.
decode
(
'latin1'
)
,
"page"
:
page
,
"time"
:
datetime
.
datetime
.
utcnow
(),
"host"
:
_get_request_header
(
request
,
'SERVER_NAME'
),
...
...
lms/djangoapps/instructor_task/api_helper.py
View file @
de91ceaa
...
...
@@ -88,7 +88,7 @@ def _get_xmodule_instance_args(request, task_id):
"""
request_info
=
{
'username'
:
request
.
user
.
username
,
'ip'
:
request
.
META
[
'REMOTE_ADDR'
],
'agent'
:
request
.
META
.
get
(
'HTTP_USER_AGENT'
,
''
),
'agent'
:
request
.
META
.
get
(
'HTTP_USER_AGENT'
,
''
)
.
decode
(
'latin1'
)
,
'host'
:
request
.
META
[
'SERVER_NAME'
],
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment