lavender/issuer/manager_test.go

52 lines
1.3 KiB
Go
Raw Normal View History

2023-10-04 14:51:38 +01:00
package issuer
import (
"github.com/1f349/lavender/utils"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/url"
"strings"
"testing"
)
var testAddrUrl = func() utils.JsonUrl {
a, err := url.Parse("https://example.com")
if err != nil {
panic(err)
}
return utils.JsonUrl{URL: a}
}()
func testBody() io.ReadCloser {
return io.NopCloser(strings.NewReader("{}"))
}
2023-10-08 15:24:59 +01:00
func TestManager_CheckNamespace(t *testing.T) {
2023-10-04 14:51:38 +01:00
httpGet = func(url string) (resp *http.Response, err error) {
return &http.Response{StatusCode: http.StatusOK, Body: testBody()}, nil
}
2024-09-02 22:54:03 +01:00
manager, err := NewManager(map[string]SsoConfig{
"example.com": {
Addr: testAddrUrl,
2023-10-04 14:51:38 +01:00
},
})
assert.NoError(t, err)
assert.True(t, manager.CheckNamespace("example.com"))
assert.False(t, manager.CheckNamespace("missing.example.com"))
}
func TestManager_FindServiceFromLogin(t *testing.T) {
httpGet = func(url string) (resp *http.Response, err error) {
return &http.Response{StatusCode: http.StatusOK, Body: testBody()}, nil
}
2024-09-02 22:54:03 +01:00
manager, err := NewManager(map[string]SsoConfig{
"example.com": {
Addr: testAddrUrl,
2023-10-04 14:51:38 +01:00
},
})
assert.NoError(t, err)
assert.Equal(t, manager.FindServiceFromLogin("jane@example.com"), manager.m["example.com"])
assert.Nil(t, manager.FindServiceFromLogin("jane@missing.example.com"))
}