mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 23:54:10 +00:00
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
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("{}"))
|
|
}
|
|
|
|
func TestManager_CheckNamespace(t *testing.T) {
|
|
httpGet = func(url string) (resp *http.Response, err error) {
|
|
return &http.Response{StatusCode: http.StatusOK, Body: testBody()}, nil
|
|
}
|
|
manager, err := NewManager("example.org", []SsoConfig{
|
|
{
|
|
Addr: testAddrUrl,
|
|
Namespace: "example.com",
|
|
},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.True(t, manager.CheckNamespace("example.org"))
|
|
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
|
|
}
|
|
manager, err := NewManager("example.org", []SsoConfig{
|
|
{
|
|
Addr: testAddrUrl,
|
|
Namespace: "example.com",
|
|
},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, manager.FindServiceFromLogin("jane@example.org"), MeWellKnown)
|
|
assert.Equal(t, manager.FindServiceFromLogin("jane@example.com"), manager.m["example.com"])
|
|
assert.Nil(t, manager.FindServiceFromLogin("jane@missing.example.com"))
|
|
}
|