*: fix not all migrations using db_alias
This commit is contained in:
parent
03b1a67b44
commit
af8cdb34ee
|
@ -79,7 +79,9 @@ class TestProviderOIDC(StaticLiveServerTestCase):
|
||||||
"""test OpenID Provider flow (invalid redirect URI, check error message)"""
|
"""test OpenID Provider flow (invalid redirect URI, check error message)"""
|
||||||
sleep(1)
|
sleep(1)
|
||||||
# Bootstrap all needed objects
|
# Bootstrap all needed objects
|
||||||
authorization_flow = Flow.objects.get(slug="default-provider-authorization")
|
authorization_flow = Flow.objects.get(
|
||||||
|
slug="default-provider-authorization-implicit-consent"
|
||||||
|
)
|
||||||
client = Client.objects.create(
|
client = Client.objects.create(
|
||||||
name="grafana",
|
name="grafana",
|
||||||
client_type="confidential",
|
client_type="confidential",
|
||||||
|
|
|
@ -9,7 +9,9 @@ def create_default_user(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
# We have to use a direct import here, otherwise we get an object manager error
|
# We have to use a direct import here, otherwise we get an object manager error
|
||||||
from passbook.core.models import User
|
from passbook.core.models import User
|
||||||
|
|
||||||
pbadmin, _ = User.objects.get_or_create(
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
|
pbadmin, _ = User.objects.using(db_alias).get_or_create(
|
||||||
username="pbadmin", email="root@localhost", name="passbook Default Admin"
|
username="pbadmin", email="root@localhost", name="passbook Default Admin"
|
||||||
)
|
)
|
||||||
pbadmin.set_password("pbadmin") # noqa # nosec
|
pbadmin.set_password("pbadmin") # noqa # nosec
|
||||||
|
|
|
@ -32,25 +32,27 @@ def create_default_source_enrollment_flow(
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
# Create a policy that only allows this flow when doing an SSO Request
|
# Create a policy that only allows this flow when doing an SSO Request
|
||||||
flow_policy = ExpressionPolicy.objects.create(
|
flow_policy = ExpressionPolicy.objects.using(db_alias).create(
|
||||||
name="default-source-enrollment-if-sso", expression=FLOW_POLICY_EXPRESSION
|
name="default-source-enrollment-if-sso", expression=FLOW_POLICY_EXPRESSION
|
||||||
)
|
)
|
||||||
|
|
||||||
# This creates a Flow used by sources to enroll users
|
# This creates a Flow used by sources to enroll users
|
||||||
# It makes sure that a username is set, and if not, prompts the user for a Username
|
# It makes sure that a username is set, and if not, prompts the user for a Username
|
||||||
flow = Flow.objects.create(
|
flow = Flow.objects.using(db_alias).create(
|
||||||
name="default-source-enrollment",
|
name="default-source-enrollment",
|
||||||
slug="default-source-enrollment",
|
slug="default-source-enrollment",
|
||||||
designation=FlowDesignation.ENROLLMENT,
|
designation=FlowDesignation.ENROLLMENT,
|
||||||
)
|
)
|
||||||
PolicyBinding.objects.create(policy=flow_policy, target=flow, order=0)
|
PolicyBinding.objects.using(db_alias).create(
|
||||||
|
policy=flow_policy, target=flow, order=0
|
||||||
|
)
|
||||||
|
|
||||||
# PromptStage to ask user for their username
|
# PromptStage to ask user for their username
|
||||||
prompt_stage = PromptStage.objects.create(
|
prompt_stage = PromptStage.objects.using(db_alias).create(
|
||||||
name="default-source-enrollment-username-prompt",
|
name="default-source-enrollment-username-prompt",
|
||||||
)
|
)
|
||||||
prompt_stage.fields.add(
|
prompt_stage.fields.add(
|
||||||
Prompt.objects.create(
|
Prompt.objects.using(db_alias).create(
|
||||||
field_key="username",
|
field_key="username",
|
||||||
label="Username",
|
label="Username",
|
||||||
type=FieldTypes.TEXT,
|
type=FieldTypes.TEXT,
|
||||||
|
@ -59,20 +61,30 @@ def create_default_source_enrollment_flow(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Policy to only trigger prompt when no username is given
|
# Policy to only trigger prompt when no username is given
|
||||||
prompt_policy = ExpressionPolicy.objects.create(
|
prompt_policy = ExpressionPolicy.objects.using(db_alias).create(
|
||||||
name="default-source-enrollment-if-username",
|
name="default-source-enrollment-if-username",
|
||||||
expression=PROMPT_POLICY_EXPRESSION,
|
expression=PROMPT_POLICY_EXPRESSION,
|
||||||
)
|
)
|
||||||
|
|
||||||
# UserWrite stage to create the user, and login stage to log user in
|
# UserWrite stage to create the user, and login stage to log user in
|
||||||
user_write = UserWriteStage.objects.create(name="default-source-enrollment-write")
|
user_write = UserWriteStage.objects.using(db_alias).create(
|
||||||
user_login = UserLoginStage.objects.create(name="default-source-enrollment-login")
|
name="default-source-enrollment-write"
|
||||||
|
)
|
||||||
|
user_login = UserLoginStage.objects.using(db_alias).create(
|
||||||
|
name="default-source-enrollment-login"
|
||||||
|
)
|
||||||
|
|
||||||
binding = FlowStageBinding.objects.create(flow=flow, stage=prompt_stage, order=0)
|
binding = FlowStageBinding.objects.using(db_alias).create(
|
||||||
PolicyBinding.objects.create(policy=prompt_policy, target=binding)
|
flow=flow, stage=prompt_stage, order=0
|
||||||
|
)
|
||||||
|
PolicyBinding.objects.using(db_alias).create(policy=prompt_policy, target=binding)
|
||||||
|
|
||||||
FlowStageBinding.objects.create(flow=flow, stage=user_write, order=1)
|
FlowStageBinding.objects.using(db_alias).create(
|
||||||
FlowStageBinding.objects.create(flow=flow, stage=user_login, order=2)
|
flow=flow, stage=user_write, order=1
|
||||||
|
)
|
||||||
|
FlowStageBinding.objects.using(db_alias).create(
|
||||||
|
flow=flow, stage=user_login, order=2
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_default_source_authentication_flow(
|
def create_default_source_authentication_flow(
|
||||||
|
@ -91,22 +103,26 @@ def create_default_source_authentication_flow(
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
# Create a policy that only allows this flow when doing an SSO Request
|
# Create a policy that only allows this flow when doing an SSO Request
|
||||||
flow_policy = ExpressionPolicy.objects.create(
|
flow_policy = ExpressionPolicy.objects.using(db_alias).create(
|
||||||
name="default-source-authentication-if-sso", expression=FLOW_POLICY_EXPRESSION
|
name="default-source-authentication-if-sso", expression=FLOW_POLICY_EXPRESSION
|
||||||
)
|
)
|
||||||
|
|
||||||
# This creates a Flow used by sources to authenticate users
|
# This creates a Flow used by sources to authenticate users
|
||||||
flow = Flow.objects.create(
|
flow = Flow.objects.using(db_alias).create(
|
||||||
name="default-source-authentication",
|
name="default-source-authentication",
|
||||||
slug="default-source-authentication",
|
slug="default-source-authentication",
|
||||||
designation=FlowDesignation.AUTHENTICATION,
|
designation=FlowDesignation.AUTHENTICATION,
|
||||||
)
|
)
|
||||||
PolicyBinding.objects.create(policy=flow_policy, target=flow, order=0)
|
PolicyBinding.objects.using(db_alias).create(
|
||||||
|
policy=flow_policy, target=flow, order=0
|
||||||
|
)
|
||||||
|
|
||||||
user_login = UserLoginStage.objects.create(
|
user_login = UserLoginStage.objects.using(db_alias).create(
|
||||||
name="default-source-authentication-login"
|
name="default-source-authentication-login"
|
||||||
)
|
)
|
||||||
FlowStageBinding.objects.create(flow=flow, stage=user_login, order=0)
|
FlowStageBinding.objects.using(db_alias).create(
|
||||||
|
flow=flow, stage=user_login, order=0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -18,20 +18,22 @@ def create_default_provider_authz_flow(
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
# Empty flow for providers where consent is implicitly given
|
# Empty flow for providers where consent is implicitly given
|
||||||
Flow.objects.create(
|
Flow.objects.using(db_alias).create(
|
||||||
name="Authorize Application",
|
name="Authorize Application",
|
||||||
slug="default-provider-authorization-implicit-consent",
|
slug="default-provider-authorization-implicit-consent",
|
||||||
designation=FlowDesignation.AUTHORIZATION,
|
designation=FlowDesignation.AUTHORIZATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Flow with consent form to obtain explicit user consent
|
# Flow with consent form to obtain explicit user consent
|
||||||
flow = Flow.objects.create(
|
flow = Flow.objects.using(db_alias).create(
|
||||||
name="Authorize Application",
|
name="Authorize Application",
|
||||||
slug="default-provider-authorization-explicit-consent",
|
slug="default-provider-authorization-explicit-consent",
|
||||||
designation=FlowDesignation.AUTHORIZATION,
|
designation=FlowDesignation.AUTHORIZATION,
|
||||||
)
|
)
|
||||||
stage = ConsentStage.objects.create(name="default-provider-authorization-consent")
|
stage = ConsentStage.objects.using(db_alias).create(
|
||||||
FlowStageBinding.objects.create(flow=flow, stage=stage, order=0)
|
name="default-provider-authorization-consent"
|
||||||
|
)
|
||||||
|
FlowStageBinding.objects.using(db_alias).create(flow=flow, stage=stage, order=0)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
Reference in New Issue