Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
6356e177
Commit
6356e177
authored
7 years ago
by
Harsha Kethineni
Browse files
Options
Downloads
Patches
Plain Diff
tested new functionality of access log reports
parent
7a5119c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/handlers/reporthandler.py
+14
-13
14 additions, 13 deletions
api/handlers/reporthandler.py
test/integration_tests/python/test_reports.py
+45
-2
45 additions, 2 deletions
test/integration_tests/python/test_reports.py
with
59 additions
and
15 deletions
api/handlers/reporthandler.py
+
14
−
13
View file @
6356e177
...
...
@@ -16,24 +16,24 @@ from ..web import base
EIGHTEEN_YEARS_IN_SEC
=
18
*
365.25
*
24
*
60
*
60
BYTES_IN_MEGABYTE
=
float
(
1
<<
20
)
ACCESS_LOG_FIELDS
=
[
"
context.session.label
"
,
"
context.project.id
"
,
"
context.subject.label
"
,
"
context.ticket_id
"
,
"
_id
"
,
"
access_type
"
,
"
context.acquisition.id
"
,
"
context.acquisition.label
"
,
"
timestamp
"
,
"
access_type
"
,
"
context.group.id
"
,
"
request_method
"
,
"
context.subject.id
"
,
"
request_path
"
,
"
context.group.label
"
,
"
context.project.id
"
,
"
context.project.label
"
,
"
origin.id
"
,
"
_id
"
,
"
context.session.id
"
,
"
origin.type
"
"
context.session.label
"
,
"
context.subject.id
"
,
"
context.subject.label
"
,
"
context.ticket_id
"
,
"
origin.id
"
,
"
origin.type
"
,
"
request_method
"
,
"
request_path
"
,
"
timestamp
"
]
class
APIReportException
(
Exception
):
...
...
@@ -71,6 +71,7 @@ class ReportHandler(base.RequestHandler):
for
doc
in
report
.
build
():
writer
.
writerow
(
doc
)
# Need to close and reopen file to flush buffer into file
csv_file
.
close
()
self
.
response
.
app_iter
=
open
(
os
.
path
.
join
(
tempdir
.
name
,
'
acceslog.csv
'
),
'
r
'
)
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
text/csv
'
...
...
@@ -504,7 +505,7 @@ class AccessLogReport(Report):
if
limit
<
1
:
raise
APIReportParamsException
(
'
Limit must be an integer greater than 0.
'
)
for
access_type
in
access_types
:
if
access_type
not
in
[
'
user_login
'
,
'
view_container
'
]:
if
access_type
not
in
[
'
user_login
'
,
'
view_container
'
,
'
download_file
'
]:
raise
APIReportParamsException
(
'
Not a valid access type
'
)
self
.
start_date
=
start_date
...
...
This diff is collapsed.
Click to expand it.
test/integration_tests/python/test_reports.py
+
45
−
2
View file @
6356e177
...
...
@@ -2,7 +2,6 @@ import calendar
import
copy
import
datetime
# create timestamps for report filtering
today
=
datetime
.
datetime
.
today
()
ts_format
=
'
{:%Y-%m-%dT%H:%M:%S+00:00}
'
...
...
@@ -93,7 +92,7 @@ def test_project_report(data_builder, as_admin, as_user):
assert
len
(
project_report
[
'
projects
'
])
==
2
def
test_access_log_report
(
with_user
,
as_user
,
as_admin
):
def
test_access_log_report
(
data_builder
,
with_user
,
as_user
,
as_admin
):
# try to get access log report as user
r
=
as_user
.
get
(
'
/report/accesslog
'
)
assert
r
.
status_code
==
403
...
...
@@ -135,6 +134,50 @@ def test_access_log_report(with_user, as_user, as_admin):
assert
len
(
accesslog
)
==
1
assert
accesslog
[
0
][
'
access_type
'
]
==
'
user_login
'
# get access log report of certain subject
project
=
data_builder
.
create_project
()
r
=
as_admin
.
post
(
'
/sessions
'
,
json
=
{
'
project
'
:
project
,
'
label
'
:
'
test-accesslog-session
'
,
'
timestamp
'
:
'
1979-01-01T00:00:00+00:00
'
,
'
subject
'
:
{
'
code
'
:
'
compliant5
'
}
})
assert
r
.
ok
session
=
r
.
json
()[
'
_id
'
]
r
=
as_admin
.
get
(
'
/sessions/
'
+
session
)
assert
r
.
ok
session
=
r
.
json
()[
'
_id
'
]
r
=
as_admin
.
get
(
'
/sessions/
'
+
session
)
assert
r
.
ok
r
=
as_admin
.
get
(
'
/report/accesslog
'
,
params
=
{
'
subject
'
:
'
compliant5
'
})
assert
r
.
ok
for
count
,
log
in
enumerate
(
r
.
json
(),
start
=
1
):
assert
log
.
get
(
'
context
'
,
{}).
get
(
'
subject
'
,
{}).
get
(
'
label
'
)
==
'
compliant5
'
assert
count
==
2
r
=
as_admin
.
delete
(
'
/sessions/
'
+
session
)
data_builder
.
delete_project
(
project
,
recursive
=
True
)
# get access log report of certain access types
r
=
as_admin
.
get
(
'
/report/accesslog
'
,
params
=
{
'
access_types
'
:
[
'
user_login
'
,
'
view_container
'
]})
assert
r
.
ok
ul
,
vc
=
False
,
False
# test that each item in log is either view_container or user_login
for
log
in
r
.
json
():
assert
log
.
get
(
'
access_type
'
)
in
[
'
user_login
'
,
'
view_container
'
]
if
log
.
get
(
'
access_type
'
)
==
'
user_login
'
:
ul
=
True
elif
log
.
get
(
'
access_type
'
)
==
'
view_container
'
:
vc
=
True
assert
ul
and
vc
# Download .csv file
r
=
as_admin
.
get
(
'
/report/accesslog
'
,
params
=
{
'
csv
'
:
'
true
'
})
assert
r
.
ok
r
.
content
[
0
][:
3
]
==
'
_id
'
def
test_usage_report
(
data_builder
,
file_form
,
as_user
,
as_admin
):
# try to get usage report as user
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment