samltest

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIssuer = security.NewIssuer(func(opt *security.DefaultIssuerDetails) {
	*opt = security.DefaultIssuerDetails{
		Protocol:    "http",
		Domain:      "vms.com",
		Port:        8080,
		ContextPath: webtest.DefaultContextPath,
		IncludePort: true,
	}
})

Functions

func MakeAuthnRequest

func MakeAuthnRequest(sp saml.ServiceProvider, idpUrl string) string

MakeAuthnRequest create a SAML AuthnRequest, sign it and returns

func MockAssertion

func MockAssertion(opts ...AssertionOptions) *saml.Assertion

func MockAttribute

func MockAttribute(name, value string, opts ...AttributeOptions) saml.Attribute

func MockLogoutResponse

func MockLogoutResponse(opts ...LogoutResponseOptions) *saml.LogoutResponse

func MustNewMockedIDP

func MustNewMockedIDP(opts ...IDPMockOptions) *saml.IdentityProvider

MustNewMockedIDP similar to NewMockedIDP, panic instead of returning error

func MustNewMockedSP

func MustNewMockedSP(opts ...SPMockOptions) *saml.ServiceProvider

MustNewMockedSP similar to NewMockedSP, panic instead of returning error

func NewMockedIDP

func NewMockedIDP(opts ...IDPMockOptions) (*saml.IdentityProvider, error)

NewMockedIDP create a mocked IDP with given IDPMockOptions. Returns error if any mocked value are incorrect. e.g. file not exists

func NewMockedSP

func NewMockedSP(opts ...SPMockOptions) (*saml.ServiceProvider, error)

NewMockedSP create a mocked SP with given SPMockOptions. Returns error if any mocked value are incorrect. e.g. file not exists

func RequestWithSAMLPostBinding

func RequestWithSAMLPostBinding[T BindableSamlTypes](samlObj *T, relayState string) webtest.RequestOptions

RequestWithSAMLPostBinding returns a webtest.RequestOptions that inject given SAML Request/Response using Post binding. Note: request need to be POST

Types

type AssertionOption

type AssertionOption struct {
	Issuer       string // entity ID
	NameID       string
	NameIDFormat string
	Recipient    string
	Audience     string // entity ID
	RequestID    string
	Attributes   []saml.Attribute
}

type AssertionOptions

type AssertionOptions func(opt *AssertionOption)

type AttributeOptions

type AttributeOptions func(attr *saml.Attribute)

type BindableSamlTypes

type BindableSamlTypes interface {
	saml.LogoutRequest | saml.LogoutResponse | saml.AuthnRequest | saml.Response
}

type BindingParseResult

type BindingParseResult struct {
	Binding string
	Values  url.Values
	Encoded string
	Decoded []byte
}

func ParseBinding

func ParseBinding[T samlutils.ParsableSamlTypes](resp *http.Response, dest *T) (ret BindingParseResult, err error)

ParseBinding parse redirect/post binding from given HTTP response

type ClientStoreMockOption

type ClientStoreMockOption struct {
	Clients           []samlctx.SamlClient
	SPs               []*saml.ServiceProvider
	ClientsProperties map[string]MockedClientProperties
}

type ClientStoreMockOptions

type ClientStoreMockOptions func(opt *ClientStoreMockOption)

func ClientsWithPropertiesPrefix

func ClientsWithPropertiesPrefix(appCfg bootstrap.ApplicationConfig, prefix string) ClientStoreMockOptions

ClientsWithPropertiesPrefix returns a ClientStoreMockOptions that bind a map of properties from application config with given prefix

func ClientsWithSPs

func ClientsWithSPs(sps ...*saml.ServiceProvider) ClientStoreMockOptions

ClientsWithSPs returns a ClientStoreMockOptions that convert given SPs to Clients

type ExtIDPProperties

type ExtIDPProperties struct {
	Domain string `json:"domain"`
	Name   string `json:"name"`
	IdName string `json:"id-name"`
}

type ExtSamlMetadata

type ExtSamlMetadata struct {
	EntityId         string
	Domain           string
	Source           string
	Name             string
	IdName           string
	RequireSignature bool
	TrustCheck       bool
	TrustedKeys      []string
}

type IDPMockOption

type IDPMockOption struct {
	Properties IDPProperties
}

type IDPMockOptions

type IDPMockOptions func(opt *IDPMockOption)

func IDPWithPropertiesPrefix

func IDPWithPropertiesPrefix(appCfg bootstrap.ApplicationConfig, prefix string) IDPMockOptions

IDPWithPropertiesPrefix returns a IDP mock option that bind properties from application config and with given prefix

type IDPProperties

type IDPProperties struct {
	ProviderProperties
	ExtIDPProperties
	SSOPath string `json:"sso"`
	SLOPath string `json:"slo"`
}

type IdpManagerMockOption

type IdpManagerMockOption struct {
	IDPList       []idp.IdentityProvider
	IDPProperties map[string]IDPProperties
	Delegates     []idp.IdentityProviderManager
}

type IdpManagerMockOptions

type IdpManagerMockOptions func(opt *IdpManagerMockOption)

func IDPsWithFallback

func IDPsWithFallback(delegates ...idp.IdentityProviderManager) IdpManagerMockOptions

IDPsWithFallback returns a IdpManagerMockOptions that set a fallback implementation for non-SAML IDPs

func IDPsWithPropertiesPrefix

func IDPsWithPropertiesPrefix(appCfg bootstrap.ApplicationConfig, prefix string) IdpManagerMockOptions

IDPsWithPropertiesPrefix returns a IdpManagerMockOptions that bind a map of properties from application config and with given prefix

type LogoutResponseOption

type LogoutResponseOption struct {
	Issuer    string // entity ID
	Recipient string
	Audience  string // entity ID
	RequestID string
	Success   bool
}

type LogoutResponseOptions

type LogoutResponseOptions func(opt *LogoutResponseOption)

type MockSamlClientStore

type MockSamlClientStore struct {
	// contains filtered or unexported fields
}

func NewMockedClientStore

func NewMockedClientStore(opts ...ClientStoreMockOptions) *MockSamlClientStore

func (*MockSamlClientStore) GetAllSamlClient

func (t *MockSamlClientStore) GetAllSamlClient(_ context.Context) ([]samlctx.SamlClient, error)

func (*MockSamlClientStore) GetSamlClientByEntityId

func (t *MockSamlClientStore) GetSamlClientByEntityId(_ context.Context, id string) (samlctx.SamlClient, error)

type MockedClientOption

type MockedClientOption struct {
	Properties MockedClientProperties
	SP         *saml.ServiceProvider
}

type MockedClientOptions

type MockedClientOptions func(opt *MockedClientOption)

type MockedClientProperties

type MockedClientProperties struct {
	SPProperties
	SkipEncryption            bool                      `json:"skip-encryption"`
	SkipSignatureVerification bool                      `json:"skip-signature-verification"`
	TenantRestriction         utils.CommaSeparatedSlice `json:"tenant-restriction"`
	TenantRestrictionType     string                    `json:"tenant-restriction-type"`
}

type MockedIdpManager

type MockedIdpManager struct {
	// contains filtered or unexported fields
}

func NewMockedIdpManager

func NewMockedIdpManager(opts ...IdpManagerMockOptions) *MockedIdpManager

NewMockedIdpManager create a mocked samllogin.SamlIdentityProviderManager that returns SAML IDP based on given options

func (MockedIdpManager) GetIdentityProviderByDomain

func (m MockedIdpManager) GetIdentityProviderByDomain(ctx context.Context, domain string) (idp.IdentityProvider, error)

func (MockedIdpManager) GetIdentityProviderByEntityId

func (m MockedIdpManager) GetIdentityProviderByEntityId(ctx context.Context, entityId string) (idp.IdentityProvider, error)

func (MockedIdpManager) GetIdentityProvidersWithFlow

func (m MockedIdpManager) GetIdentityProvidersWithFlow(ctx context.Context, flow idp.AuthenticationFlow) (ret []idp.IdentityProvider)

type MockedIdpProvider

type MockedIdpProvider struct {
	ExtSamlMetadata
}

func NewMockedIdpProvider

func NewMockedIdpProvider(opts ...IDPMockOptions) *MockedIdpProvider

func (MockedIdpProvider) Domain

func (i MockedIdpProvider) Domain() string

func (MockedIdpProvider) EntityId

func (i MockedIdpProvider) EntityId() string

func (MockedIdpProvider) ExternalIdName

func (i MockedIdpProvider) ExternalIdName() string

func (MockedIdpProvider) ExternalIdpName

func (i MockedIdpProvider) ExternalIdpName() string

func (MockedIdpProvider) GetAutoCreateUserDetails

func (i MockedIdpProvider) GetAutoCreateUserDetails() security.AutoCreateUserDetails

func (MockedIdpProvider) GetMetadataTrustedKeys

func (i MockedIdpProvider) GetMetadataTrustedKeys() []string

func (MockedIdpProvider) MetadataLocation

func (i MockedIdpProvider) MetadataLocation() string

func (MockedIdpProvider) ShouldMetadataRequireSignature

func (i MockedIdpProvider) ShouldMetadataRequireSignature() bool

func (MockedIdpProvider) ShouldMetadataTrustCheck

func (i MockedIdpProvider) ShouldMetadataTrustCheck() bool

type MockedSamlAssertionAuthentication

type MockedSamlAssertionAuthentication struct {
	Account       security.Account
	DetailsMap    map[string]interface{}
	SamlAssertion *saml.Assertion
}

func (*MockedSamlAssertionAuthentication) Assertion

func (*MockedSamlAssertionAuthentication) Details

func (sa *MockedSamlAssertionAuthentication) Details() interface{}

func (*MockedSamlAssertionAuthentication) Permissions

func (*MockedSamlAssertionAuthentication) Principal

func (sa *MockedSamlAssertionAuthentication) Principal() interface{}

func (*MockedSamlAssertionAuthentication) State

type MockedSamlClient

type MockedSamlClient struct {
	EntityId                             string
	MetadataSource                       string
	SkipAssertionEncryption              bool
	SkipAuthRequestSignatureVerification bool
	MetadataRequireSignature             bool
	MetadataTrustCheck                   bool
	MetadataTrustedKeys                  []string
	TenantRestrictions                   utils.StringSet
	TenantRestrictionType                string
}

func NewMockedSamlClient

func NewMockedSamlClient(opts ...MockedClientOptions) *MockedSamlClient

func (MockedSamlClient) GetEntityId

func (c MockedSamlClient) GetEntityId() string

func (MockedSamlClient) GetMetadataSource

func (c MockedSamlClient) GetMetadataSource() string

func (MockedSamlClient) GetMetadataTrustedKeys

func (c MockedSamlClient) GetMetadataTrustedKeys() []string

func (MockedSamlClient) GetTenantRestrictionType

func (c MockedSamlClient) GetTenantRestrictionType() string

func (MockedSamlClient) GetTenantRestrictions

func (c MockedSamlClient) GetTenantRestrictions() utils.StringSet

func (MockedSamlClient) ShouldMetadataRequireSignature

func (c MockedSamlClient) ShouldMetadataRequireSignature() bool

func (MockedSamlClient) ShouldMetadataTrustCheck

func (c MockedSamlClient) ShouldMetadataTrustCheck() bool

func (MockedSamlClient) ShouldSkipAssertionEncryption

func (c MockedSamlClient) ShouldSkipAssertionEncryption() bool

func (MockedSamlClient) ShouldSkipAuthRequestSignatureVerification

func (c MockedSamlClient) ShouldSkipAuthRequestSignatureVerification() bool

type ProviderProperties

type ProviderProperties struct {
	EntityID         string `json:"entity-id"`
	MetadataSource   string `json:"metadata-source"`
	CertsSource      string `json:"certs"`
	PrivateKeySource string `json:"private-key"`
}

type SPMockOption

type SPMockOption struct {
	Properties SPProperties
	IDP        *saml.IdentityProvider
}

type SPMockOptions

type SPMockOptions func(opt *SPMockOption)

func SPWithIDP

func SPWithIDP(idp *saml.IdentityProvider) SPMockOptions

SPWithIDP returns a SP mock option that set given IDP

func SPWithPropertiesPrefix

func SPWithPropertiesPrefix(appCfg bootstrap.ApplicationConfig, prefix string) SPMockOptions

SPWithPropertiesPrefix returns a SP mock option that bind properties from application config and with given prefix

type SPProperties

type SPProperties struct {
	ProviderProperties
	ACSPath string         `json:"acs"`
	SLOPath string         `json:"slo"`
	IDP     *IDPProperties `json:"idp"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL