add tests for policies
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import random
|
||||||
import sys
|
import sys
|
||||||
from os import environ
|
from os import environ
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@ -17,6 +17,8 @@ from django.conf import settings
|
|||||||
from authentik.core.models import Application, Group, User
|
from authentik.core.models import Application, Group, User
|
||||||
from authentik.crypto.models import CertificateKeyPair
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
from authentik.flows.models import Flow
|
from authentik.flows.models import Flow
|
||||||
|
from authentik.policies.expression.models import ExpressionPolicy
|
||||||
|
from authentik.policies.models import PolicyBinding
|
||||||
from authentik.providers.oauth2.models import OAuth2Provider
|
from authentik.providers.oauth2.models import OAuth2Provider
|
||||||
from authentik.stages.authenticator_static.models import StaticToken
|
from authentik.stages.authenticator_static.models import StaticToken
|
||||||
from authentik.tenants.models import Domain, Tenant
|
from authentik.tenants.models import Domain, Tenant
|
||||||
@ -104,6 +106,18 @@ def provider_oauth2():
|
|||||||
tenants = [
|
tenants = [
|
||||||
# Number of user policies, group policies, expression policies
|
# Number of user policies, group policies, expression policies
|
||||||
(0, 0, 0),
|
(0, 0, 0),
|
||||||
|
(10, 0, 0),
|
||||||
|
(100, 0, 0),
|
||||||
|
(1000, 0, 0),
|
||||||
|
(0, 10, 0),
|
||||||
|
(0, 100, 0),
|
||||||
|
(0, 1000, 0),
|
||||||
|
(0, 0, 10),
|
||||||
|
(0, 0, 100),
|
||||||
|
(0, 0, 1000),
|
||||||
|
(10, 10, 10),
|
||||||
|
(100, 100, 100),
|
||||||
|
(1000, 1000, 1000),
|
||||||
]
|
]
|
||||||
|
|
||||||
for tenant in tenants:
|
for tenant in tenants:
|
||||||
@ -134,7 +148,56 @@ def provider_oauth2():
|
|||||||
)
|
)
|
||||||
application = Application.objects.create(slug="test", name="test", provider=provider)
|
application = Application.objects.create(slug="test", name="test", provider=provider)
|
||||||
|
|
||||||
# TODO: create policies
|
User.objects.bulk_create(
|
||||||
|
[
|
||||||
|
User(
|
||||||
|
username=uuid4(),
|
||||||
|
name=uuid4(),
|
||||||
|
)
|
||||||
|
for _ in range(user_policies_count)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
PolicyBinding.objects.bulk_create(
|
||||||
|
[
|
||||||
|
PolicyBinding(
|
||||||
|
user=user,
|
||||||
|
target=application,
|
||||||
|
order=random.randint(1, 1_000_000),
|
||||||
|
)
|
||||||
|
for user in User.objects.exclude(username="akadmin").exclude_anonymous()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
Group.objects.bulk_create([Group(name=uuid4()) for _ in range(group_policies_count)])
|
||||||
|
PolicyBinding.objects.bulk_create(
|
||||||
|
[
|
||||||
|
PolicyBinding(
|
||||||
|
group=group,
|
||||||
|
target=application,
|
||||||
|
order=random.randint(1, 1_000_000),
|
||||||
|
)
|
||||||
|
for group in Group.objects.exclude(name="authentik Admins")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
user.ak_groups.set(Group.objects.exclude(name="authentik Admins").order_by("?")[:1])
|
||||||
|
|
||||||
|
[
|
||||||
|
ExpressionPolicy(
|
||||||
|
name=f"test-{uuid4()}",
|
||||||
|
expression="return True",
|
||||||
|
).save()
|
||||||
|
for _ in range(expression_policies_count)
|
||||||
|
]
|
||||||
|
PolicyBinding.objects.bulk_create(
|
||||||
|
[
|
||||||
|
PolicyBinding(
|
||||||
|
policy=policy,
|
||||||
|
target=application,
|
||||||
|
order=random.randint(1, 1_000_000),
|
||||||
|
)
|
||||||
|
for policy in ExpressionPolicy.objects.filter(name__startswith="test-")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def delete():
|
def delete():
|
||||||
@ -149,8 +212,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
match action:
|
match action:
|
||||||
case "create":
|
case "create":
|
||||||
user_list()
|
# user_list()
|
||||||
login()
|
# login()
|
||||||
provider_oauth2()
|
provider_oauth2()
|
||||||
case "delete":
|
case "delete":
|
||||||
delete()
|
delete()
|
||||||
|
@ -3,7 +3,21 @@ import exec from "k6/execution";
|
|||||||
import http from "k6/http";
|
import http from "k6/http";
|
||||||
import { check, fail } from "k6";
|
import { check, fail } from "k6";
|
||||||
|
|
||||||
const testcases = [[0, 0, 0]];
|
const testcases = [
|
||||||
|
[0, 0, 0],
|
||||||
|
[10, 0, 0],
|
||||||
|
[100, 0, 0],
|
||||||
|
[1000, 0, 0],
|
||||||
|
[0, 10, 0],
|
||||||
|
[0, 100, 0],
|
||||||
|
[0, 1000, 0],
|
||||||
|
[0, 0, 10],
|
||||||
|
[0, 0, 100],
|
||||||
|
[0, 0, 1000],
|
||||||
|
[10, 10, 10],
|
||||||
|
[100, 100, 100],
|
||||||
|
[1000, 1000, 1000],
|
||||||
|
];
|
||||||
const VUs = 12;
|
const VUs = 12;
|
||||||
|
|
||||||
export const options = {
|
export const options = {
|
||||||
@ -33,7 +47,7 @@ export const options = {
|
|||||||
|
|
||||||
export function setup() {
|
export function setup() {
|
||||||
let cookies = {};
|
let cookies = {};
|
||||||
for (let vu = 1; vu <= VUs; vu++) {
|
for (let vu = 0; vu < VUs; vu++) {
|
||||||
cookies[vu] = {};
|
cookies[vu] = {};
|
||||||
for (const testcase of testcases) {
|
for (const testcase of testcases) {
|
||||||
const user_policies_count = testcase[0];
|
const user_policies_count = testcase[0];
|
||||||
@ -95,7 +109,7 @@ export function setup() {
|
|||||||
export default function (data) {
|
export default function (data) {
|
||||||
// Restore cookies
|
// Restore cookies
|
||||||
let jar = http.cookieJar();
|
let jar = http.cookieJar();
|
||||||
const vu = exec.vu.idInTest;
|
const vu = exec.vu.idInTest % VUs;
|
||||||
Object.keys(data.cookies[vu]).forEach((domain) => {
|
Object.keys(data.cookies[vu]).forEach((domain) => {
|
||||||
Object.keys(data.cookies[vu][domain]).forEach((key) => {
|
Object.keys(data.cookies[vu][domain]).forEach((key) => {
|
||||||
jar.set(`http://${domain}`, key, data.cookies[vu][domain][key][0]);
|
jar.set(`http://${domain}`, key, data.cookies[vu][domain][key][0]);
|
||||||
|
Reference in New Issue
Block a user