Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
archived-simpleSAMLphp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trust and Identity Incubator
personal-profile-page
archived-simpleSAMLphp
Commits
a54db9f2
Commit
a54db9f2
authored
2 years ago
by
Marko Ivancic
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
414c81d5
No related branches found
No related tags found
1 merge request
!10
Create script for inserting dummy data into DB
Pipeline
#82016
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/fake.php
+126
-42
126 additions, 42 deletions
bin/fake.php
with
126 additions
and
42 deletions
bin/fake.php
+
126
−
42
View file @
a54db9f2
...
...
@@ -14,69 +14,153 @@ use SimpleSAML\Module\accounting\Services\Logger;
require
'vendor/autoload.php'
;
$helpersManager
=
new
HelpersManager
();
$logger
=
new
Logger
();
$configDir
=
__DIR__
.
'/config'
;
putenv
(
"SIMPLESAMLPHP_CONFIG_DIR=
$configDir
"
);
$moduleConfiguration
=
new
ModuleConfiguration
();
$sampleUsers
=
include
'sampleUsers.php'
;
$activityTracker
=
new
ActivityTracker
(
$moduleConfiguration
,
$logger
);
$connectedServicesTracker
=
new
ConnectedServicesTracker
(
$moduleConfiguration
,
$logger
);
$start
=
new
DateTime
();
$newLine
=
"
\n
"
;
echo
"Start: "
.
$start
->
format
(
DateTime
::
ATOM
);
echo
$newLine
;
$options
=
getopt
(
'c:'
);
$options
=
getopt
(
'c:
o:a::
'
);
$
numberOfItems
=
$options
[
'c'
]
??
1000
;
$
spMetadata
=
[]
;
echo
'Number of items: '
.
$numberOfItems
;
echo
$newLine
;
if
(
isset
(
$options
[
'c'
]))
{
$numberOfItems
=
max
((
int
)
$options
[
'c'
],
100
);
doSampleUsers
(
$numberOfItems
,
$spMetadata
,
$sampleUsers
,
$activityTracker
,
$connectedServicesTracker
);
}
if
(
isset
(
$options
[
'o'
]))
{
$numberOfUsers
=
max
((
int
)
$options
[
'o'
],
100
);
$numberOfAuthentications
=
(
int
)
(
$options
[
'a'
]
??
1000
);
doRandomUsers
(
$numberOfUsers
,
$numberOfAuthentications
,
$spMetadata
,
$activityTracker
,
$connectedServicesTracker
);
}
/**/
echo
'Starting ... '
;
$startTime
=
new
DateTime
();
echo
$startTime
->
format
(
DateTime
::
ATOM
);
echo
$newLine
;
echo
'End: '
.
(
new
DateTime
())
->
format
(
DateTime
::
ATOM
);
echo
$newLine
;
$logger
=
new
Logger
();
$configDir
=
__DIR__
.
'/config'
;
putenv
(
"SIMPLESAMLPHP_CONFIG_DIR=
$configDir
"
);
$moduleConfiguration
=
new
ModuleConfiguration
();
$durationInSeconds
=
(
new
DateTime
())
->
getTimestamp
()
-
$startTime
->
getTimestamp
();
$sampleUsers
=
include
'sampleUsers.php'
;
$activityTracker
=
new
ActivityTracker
(
$moduleConfiguration
,
$logger
);
$connectedServicesTracker
=
new
ConnectedServicesTracker
(
$moduleConfiguration
,
$logger
);
function
doSampleUsers
(
int
$numberOfAuthentications
,
array
&
$spMetadata
,
$sampleUsers
,
ActivityTracker
$activityTracker
,
ConnectedServicesTracker
$connectedServicesTracker
)
{
echo
"Doing
$numberOfAuthentications
authentications for sample users.
\n
"
;
if
(
count
(
$spMetadata
)
<
100
)
{
$spMetadata
[]
=
prepareSampleSpMetadata
();
}
$happenedAt
=
new
DateTimeImmutable
(
'-12 months'
);
$spMetadata
=
[];
$spMetadata
[]
=
prepareSampleSpMetadata
();
$happenedAt
=
new
DateTimeImmutable
(
'-6 months'
);
for
(
$i
=
1
;
$i
<=
$numberOfAuthentications
;
$i
++
)
{
printSingleLine
(
'Doing item '
.
$i
);
if
(
$i
%
((
int
)(
$numberOfAuthentications
/
100
))
===
0
)
{
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'P1D'
));
if
(
count
(
$spMetadata
)
<
100
)
{
$spMetadata
[]
=
prepareSampleSpMetadata
();
}
}
$event
=
prepareEvent
(
Saml2
::
DESIGNATION
,
$sampleUsers
[
array_rand
(
$sampleUsers
)],
$spMetadata
[
array_rand
(
$spMetadata
)],
$happenedAt
);
for
(
$i
=
1
;
$i
<=
$numberOfItems
;
$i
++
)
{
printSingleLine
(
'Doing item '
.
$i
);
$activityTracker
->
process
(
$event
);
$connectedServicesTracker
->
process
(
$event
);
if
(
$i
%
((
int
)(
$numberOfItems
/
100
))
===
0
)
{
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'P1D'
));
if
(
count
(
$spMetadata
)
<
100
)
{
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'PT1H'
));
}
}
function
doRandomUsers
(
int
$numberOfUsers
,
int
$numberOfAuthentications
,
array
$spMetadata
,
ActivityTracker
$activityTracker
,
ConnectedServicesTracker
$connectedServicesTracker
)
{
echo
"Doing
$numberOfUsers
random users with
$numberOfAuthentications
authentications.
\n
"
;
while
(
count
(
$spMetadata
)
<
100
)
{
$spMetadata
[]
=
prepareSampleSpMetadata
();
}
for
(
$i
=
0
;
$i
<
$numberOfUsers
;
$i
++
)
{
$randomUser
=
prepareRandomUser
();
if
(
count
(
$spMetadata
)
<
500
)
{
$spMetadata
[]
=
prepareSampleSpMetadata
();
}
}
$event
=
prepareEvent
(
Saml2
::
DESIGNATION
,
$sampleUsers
[
array_rand
(
$sampleUsers
)],
$spMetadata
[
array_rand
(
$spMetadata
)],
$happenedAt
);
$startForUser
=
new
DateTimeImmutable
();
$happenedAt
=
new
DateTimeImmutable
(
'-12 months'
);
for
(
$j
=
0
;
$j
<
$numberOfAuthentications
;
$j
++
)
{
if
(
$numberOfAuthentications
>=
500
&&
(
$j
%
500
)
===
0
)
{
versionUser
(
$randomUser
);
}
printSingleLine
(
'Doing user '
.
$i
.
', authentication '
.
$j
);
if
(
$i
%
((
int
)(
$numberOfAuthentications
/
10
))
===
0
)
{
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'P1D'
));
}
$event
=
prepareEvent
(
Saml2
::
DESIGNATION
,
$randomUser
,
$spMetadata
[
array_rand
(
$spMetadata
)],
$happenedAt
);
$activityTracker
->
process
(
$event
);
$connectedServicesTracker
->
process
(
$event
);
$activityTracker
->
process
(
$event
);
$connectedServicesTracker
->
process
(
$event
);
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'PT1H'
));
$happenedAt
=
$happenedAt
->
add
(
new
DateInterval
(
'PT1H'
));
}
echo
"
\n
"
;
echo
'Done in '
.
((
new
DateTimeImmutable
())
->
getTimestamp
()
-
$startForUser
->
getTimestamp
())
.
" seconds.
\n
"
;
}
}
echo
$newLine
;
echo
'End: '
.
(
new
DateTime
())
->
format
(
DateTime
::
ATOM
);
echo
$newLine
;
echo
'Duration in seconds: '
.
$durationInSeconds
;
echo
$newLine
;
function
prepareRandomUser
():
array
{
$faker
=
Faker\Factory
::
create
();
$firstName
=
$faker
->
firstName
();
$lastName
=
$faker
->
lastName
();
$userName
=
strtolower
(
str_replace
(
' '
,
''
,
$firstName
.
'.'
.
$lastName
));
return
[
'uid'
=>
[
$userName
],
'sn'
=>
[
$lastName
],
'givenName'
=>
[
$firstName
],
'mail'
=>
[
$userName
.
'@'
.
$faker
->
domainName
()],
'hrEduPersonPersistentID'
=>
[
$faker
->
regexify
(
'[A-Z0-9]{64}'
)],
];
}
function
versionUser
(
array
&
$user
):
void
{
$faker
=
Faker\Factory
::
create
();
// Simulate addition of another email address.
$user
[
'mail'
][]
=
$faker
->
email
();
}
function
printSingleLine
(
string
$message
):
void
{
...
...
@@ -140,4 +224,4 @@ function prepareSampleSpMetadata(string $protocol = Saml2::DESIGNATION)
$rpMetadata
[
'name'
]
=
$faker
->
company
();
return
$rpMetadata
;
}
\ No newline at end of file
}
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