Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_signup_enabled field to OrganizationConnection #413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions management/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ type OrganizationConnection struct {
// Determines whether a connection should be displayed on this organization’s login prompt.
// Only applicable for enterprise connections. Default: true.
ShowAsButton *bool `json:"show_as_button,omitempty"`

// Determines whether organization sign-up should be enabled for this organization connection.
// Only applicable for database connections. Default: false.
// Note: IsSignupEnabled can only be true if AssignMembershipOnLogin is true.
IsSignupEnabled *bool `json:"is_signup_enabled,omitempty"`
}

// OrganizationConnectionDetails holds connection details for an Organization.
Expand Down
128 changes: 127 additions & 1 deletion management/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestOrganizationManager_Create(t *testing.T) {
configureHTTPTestRecordings(t)

orgConn := givenAnOrganizationConnectionWithoutOrgID(t)
orgConn2 := givenAnOrganizationConnectionWithoutOrgID(t)
orgConn2 := givenAnOrganizationDBConnectionWithoutOrgID(t)

org := &Organization{
Name: auth0.String(fmt.Sprintf("test-organization%v", rand.Intn(999))),
Expand Down Expand Up @@ -152,6 +152,17 @@ func TestOrganizationManager_Connection(t *testing.T) {
assert.Equal(t, orgConn, actualOrgConn)
}

func TestOrganizationManager_DBConnection(t *testing.T) {
configureHTTPTestRecordings(t)

org := givenAnOrganization(t)
orgConn := givenAnOrganizationDBConnection(t, org.GetID())

actualOrgConn, err := api.Organization.Connection(context.Background(), org.GetID(), orgConn.GetConnectionID())
assert.NoError(t, err)
assert.Equal(t, orgConn, actualOrgConn)
}

func TestOrganizationManager_UpdateConnection(t *testing.T) {
configureHTTPTestRecordings(t)

Expand All @@ -175,6 +186,74 @@ func TestOrganizationManager_UpdateConnection(t *testing.T) {
assert.Equal(t, false, actualOrgConn.GetShowAsButton())
}

// TestOrganizationManager_UpdateDBConnection tests the UpdateConnection method of OrganizationManager for Database Connection.
func TestOrganizationManager_UpdateDBConnection(t *testing.T) {
// Test when IsSignupEnabled true with AssignMembershipOnLogin false should fail
t.Run("When_signup_enabled_with_assign_membership_false_should_fail", func(t *testing.T) {
configureHTTPTestRecordings(t)
org := givenAnOrganization(t)
orgConn := givenAnOrganizationDBConnection(t, org.GetID())

err := api.Organization.UpdateConnection(
context.Background(),
org.GetID(),
orgConn.GetConnectionID(),
&OrganizationConnection{
AssignMembershipOnLogin: auth0.Bool(false),
IsSignupEnabled: auth0.Bool(true),
},
)
assert.Error(t, err, "Expected error when is_signup_enabled is true and assign_membership_on_login is false")
assert.Contains(t, err.Error(), "Only database connections with assign_membership_on_login = true support is_signup_enabled = true.")
})

// Test when IsSignupEnabled and AssignMembershipOnLogin are false, should succeed
t.Run("When_signup_and_assign_membership_are_false_should_succeed", func(t *testing.T) {
configureHTTPTestRecordings(t)
org := givenAnOrganization(t)
orgConn := givenAnOrganizationDBConnection(t, org.GetID())

err := api.Organization.UpdateConnection(
context.Background(),
org.GetID(),
orgConn.GetConnectionID(),
&OrganizationConnection{
AssignMembershipOnLogin: auth0.Bool(false),
IsSignupEnabled: auth0.Bool(false),
},
)
assert.NoError(t, err)

actualOrgConn, err := api.Organization.Connection(context.Background(), org.GetID(), orgConn.GetConnectionID())
assert.NoError(t, err)
assert.Equal(t, false, actualOrgConn.GetAssignMembershipOnLogin())
assert.Equal(t, false, actualOrgConn.GetIsSignupEnabled())
})

// Test when IsSignupEnabled with AssignMembershipOnLogin true should succeed
t.Run("When_signup_enabled_with_assign_membership_true_should_succeed", func(t *testing.T) {
configureHTTPTestRecordings(t)
org := givenAnOrganization(t)
orgConn := givenAnOrganizationDBConnection(t, org.GetID())

err := api.Organization.UpdateConnection(
context.Background(),
org.GetID(),
orgConn.GetConnectionID(),
&OrganizationConnection{
AssignMembershipOnLogin: auth0.Bool(true),
IsSignupEnabled: auth0.Bool(true),
},
)
assert.NoError(t, err)

actualOrgConn, err := api.Organization.Connection(context.Background(), org.GetID(), orgConn.GetConnectionID())
assert.NoError(t, err)
assert.Equal(t, true, actualOrgConn.GetAssignMembershipOnLogin())
assert.Equal(t, true, actualOrgConn.GetIsSignupEnabled())
})
}

func TestOrganizationManager_DeleteConnection(t *testing.T) {
configureHTTPTestRecordings(t)

Expand Down Expand Up @@ -439,6 +518,31 @@ func givenAnOrganizationConnection(t *testing.T, orgID string) *OrganizationConn
return orgConn
}

func givenAnOrganizationDBConnection(t *testing.T, orgID string) *OrganizationConnection {
client := givenAClient(t)
conn := givenAConnection(t, connectionTestCase{
connection: Connection{
Name: auth0.String(fmt.Sprintf("test-conn%v", rand.Intn(999))),
DisplayName: auth0.String(fmt.Sprintf("Test Connection %v", rand.Intn(999))),
Strategy: auth0.String(ConnectionStrategyAuth0),
EnabledClients: &[]string{
os.Getenv("AUTH0_CLIENT_ID"),
client.GetClientID(),
},
},
})
orgConn := &OrganizationConnection{
ConnectionID: conn.ID,
AssignMembershipOnLogin: auth0.Bool(true),
IsSignupEnabled: auth0.Bool(true),
}

err := api.Organization.AddConnection(context.Background(), orgID, orgConn)
require.NoError(t, err)

return orgConn
}

func givenAnOrganizationConnectionWithoutOrgID(t *testing.T) *OrganizationConnection {
client := givenAClient(t)
conn := givenAConnection(t, connectionTestCase{
Expand All @@ -461,6 +565,28 @@ func givenAnOrganizationConnectionWithoutOrgID(t *testing.T) *OrganizationConnec
return orgConn
}

func givenAnOrganizationDBConnectionWithoutOrgID(t *testing.T) *OrganizationConnection {
client := givenAClient(t)
conn := givenAConnection(t, connectionTestCase{
connection: Connection{
Name: auth0.String(fmt.Sprintf("test-conn%v", rand.Intn(999))),
DisplayName: auth0.String(fmt.Sprintf("Test Connection %v", rand.Intn(999))),
Strategy: auth0.String(ConnectionStrategyAuth0),
EnabledClients: &[]string{
os.Getenv("AUTH0_CLIENT_ID"),
client.GetClientID(),
},
},
})
orgConn := &OrganizationConnection{
ConnectionID: conn.ID,
AssignMembershipOnLogin: auth0.Bool(true),
IsSignupEnabled: auth0.Bool(true),
}

return orgConn
}

func givenAnOrganizationInvitation(t *testing.T, orgID string) *OrganizationInvitation {
t.Helper()

Expand Down
Loading