mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-24 08:12:15 +00:00
# Which Problems Are Solved In the context of moving our datastore to relational tables, Identity Provider Intents have no definition of a relational table nor any DB API that can be used to store the IDP intents as relational objects. # How the Problems Are Solved The PR follows the guidelines left in #11190 - A table `zitadel.identity_provider_intents` is created: it defines its relational constraints (foreign keys) with the other tables, as well as an ENUM to represent the state of the intent. - An IDP Intent repository has been created, which offers CRUD operations implemented as `Create`, `Get`, `Update` and `Delete` methods for the IDP intent. - The repository also defines all columns and conditions useful for performing DB operations on the IDP intents. - DB mocks have been added as well to ease testing on the `domain` package. - Reduction functions have been implemented for the existing IDP events so to keep the relational table in sync with the event store. # Additional Changes To allow testing LDAP intent flow, the `Session.FetchUser()` method has been extracted to a separate file. A corresponding mock has been created as well in `fetch_user_mock.go`. The files are mutually excluded and added at build time through go build tags: the mock is added when the `integration` tag is specified, while the real implementation is added when the same tag IS NOT added to the build tags. # Additional Context - Closes #11190 --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Silvan <[email protected]>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
//go:build integration
|
|
|
|
package ldap
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/brianvoe/gofakeit/v6"
|
|
"github.com/go-ldap/ldap/v3"
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/idp"
|
|
)
|
|
|
|
const (
|
|
FailingUser = "IAM FAIL"
|
|
FailingPsw = "test failed successfully"
|
|
)
|
|
|
|
// FetchUser implements the [idp.Session] interface.
|
|
//
|
|
// This is a mock implementation of [idp.Session.FetchUser] that is used
|
|
// during integration tests and substitutes the real [idp.Session.FetchUser]
|
|
// implementation.
|
|
//
|
|
// This has been done to allow writing integration tests against a
|
|
// fake (external) LDAP server.
|
|
//
|
|
// The substitution/overloading is done through build tags.
|
|
//
|
|
// When the LDAP start intent is called with `username = [FailingUser]` and
|
|
// `password = [FailingPsw]`, the method return [ErrFailedLogin] to be able
|
|
// to mock an intent failed event.
|
|
func (s *Session) FetchUser(_ context.Context) (_ idp.User, err error) {
|
|
if s.User == FailingUser && s.Password == FailingPsw {
|
|
return nil, ErrFailedLogin
|
|
}
|
|
|
|
usr := NewUser(
|
|
gofakeit.UUID(),
|
|
gofakeit.FirstName(),
|
|
gofakeit.LastName(),
|
|
gofakeit.Name(),
|
|
gofakeit.Name(),
|
|
gofakeit.Name(),
|
|
domain.EmailAddress(gofakeit.Email()),
|
|
true,
|
|
domain.PhoneNumber(gofakeit.Phone()),
|
|
true,
|
|
language.English,
|
|
gofakeit.URL(),
|
|
gofakeit.UUID(),
|
|
)
|
|
|
|
s.Entry = &ldap.Entry{
|
|
DN: s.Provider.baseDN,
|
|
Attributes: []*ldap.EntryAttribute{
|
|
{Name: "uid", Values: []string{gofakeit.UUID()}},
|
|
{Name: "givenName", Values: []string{gofakeit.FirstName()}},
|
|
{Name: "sn", Values: []string{gofakeit.LastName()}},
|
|
{Name: "mail", Values: []string{gofakeit.Email()}},
|
|
{Name: "telephoneNumber", Values: []string{gofakeit.Phone()}},
|
|
{Name: "displayName", Values: []string{gofakeit.Name()}},
|
|
},
|
|
}
|
|
return usr, nil
|
|
}
|