feat: a Fields pane for anything but a secret, first for Azure accounts: fields and groups to move through, filter and copy (#7)
This commit was merged in pull request #7.
This commit is contained in:
1 parent
f6c4f5f6f6
commit
71396f1e02
13 files changed
+404
-37
No files matched your search
@@ -1,7 +1,17 @@
|
||||
package azure
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/provider"
|
||||
)
|
||||
@@ -25,7 +35,7 @@ func TestAccount(t *testing.T) {
|
||||
got[f.Label] = f.Value
|
||||
}
|
||||
want := map[string]string{
|
||||
"name": "Alice Example", "user": "alice@contoso.com", "tenant": "Contoso · t1",
|
||||
"name": "Alice Example", "user": "alice@contoso.com", "tenant": "Contoso", "tenant ID": "t1",
|
||||
"object ID": "11111111-2222-3333-4444-555555555555", "sign-in": "MFA · password",
|
||||
"roles": "Global Administrator, role aaaaaaaa", "subs": "3 · default platform",
|
||||
}
|
||||
@@ -44,7 +54,7 @@ func TestAccount(t *testing.T) {
|
||||
// Before any token: what az's list says.
|
||||
claims = nil
|
||||
a, _ = p.Account()
|
||||
if len(a.Fields) != 3 || a.Copy != "" {
|
||||
if len(a.Fields) != 4 || a.Copy != "" {
|
||||
t.Errorf("without a token: %+v", a)
|
||||
}
|
||||
if _, ok := (&Provider{}).Account(); ok {
|
||||
@@ -65,3 +75,40 @@ func TestSignInMethods(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type staticToken struct{}
|
||||
|
||||
func (staticToken) GetToken(context.Context, policy.TokenRequestOptions) (azcore.AccessToken, error) {
|
||||
return azcore.AccessToken{Token: "tok", ExpiresOn: time.Now().Add(time.Hour)}, nil
|
||||
}
|
||||
|
||||
type graphPages map[string]string // by URL
|
||||
|
||||
func (g graphPages) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
body, ok := g[r.URL.String()]
|
||||
if !ok || r.Header.Get("Authorization") != "Bearer tok" {
|
||||
return &http.Response{StatusCode: 404, Status: "404 Not Found", Body: io.NopCloser(strings.NewReader(`{}`))}, nil
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Status: "200 OK", Body: io.NopCloser(strings.NewReader(body))}, nil
|
||||
}
|
||||
|
||||
func TestGroups(t *testing.T) {
|
||||
next := "https://graph.microsoft.com/v1.0/next"
|
||||
p := &Provider{
|
||||
cred: staticToken{},
|
||||
account: &accountDetails{account: account{user: "alice@contoso.com"}},
|
||||
graphClient: &http.Client{Transport: graphPages{
|
||||
graphGroups: `{"value":[{"@odata.type":"#microsoft.graph.group","displayName":"vault readers"},
|
||||
{"@odata.type":"#microsoft.graph.directoryRole","displayName":"Global Reader"}],"@odata.nextLink":"` + next + `"}`,
|
||||
next: `{"value":[{"@odata.type":"#microsoft.graph.group","displayName":"Platform team"}]}`,
|
||||
}},
|
||||
}
|
||||
got, err := p.Groups(context.Background())
|
||||
if err != nil || !slices.Equal(got, []string{"Platform team", "vault readers"}) {
|
||||
t.Errorf("groups %q, %v", got, err)
|
||||
}
|
||||
p.account.cloud = "AzureChinaCloud"
|
||||
if _, err := p.Groups(context.Background()); !errors.Is(err, provider.ErrUnsupported) {
|
||||
t.Errorf("other cloud: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user