Skip to content

Commit

Permalink
is: Try
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 25, 2024
1 parent 1cb34cd commit b33ef4f
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions pkg/identityserver/email_notification_preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package identityserver

import (
"fmt"
"os"
"path/filepath"
"testing"

"go.thethings.network/lorawan-stack/v3/pkg/identityserver/storetest"
Expand All @@ -30,49 +27,37 @@ import (
func TestEmailNotificationPreferences(t *testing.T) {
p := &storetest.Population{}

adminUsr := p.NewUser()
adminUsr.Admin = true
admin := p.NewUser()
admin.Admin = true
adminKey, _ := p.NewAPIKey(admin.GetEntityIdentifiers(), ttnpb.Right_RIGHT_ALL)
adminCreds := rpcCreds(adminKey)

usr1 := p.NewUser()
usr1.EmailNotificationPreferences = &ttnpb.EmailNotificationPreferences{
Types: []ttnpb.NotificationType{
ttnpb.NotificationType_API_KEY_CREATED,
},
}
limitedKey, _ := p.NewAPIKey(usr1.GetEntityIdentifiers(),
ttnpb.Right_RIGHT_USER_INFO,
ttnpb.Right_RIGHT_USER_SETTINGS_BASIC,
ttnpb.Right_RIGHT_USER_SETTINGS_API_KEYS,
)
limitedCreds := rpcCreds(limitedKey)
app1 := p.NewApplication(usr1.GetOrganizationOrUserIdentifiers())

t.Parallel()
a, ctx := test.New(t)
// is.config.AdminRights.All = true
// is.config.Email.Provider = "dir"
// tempDir := t.TempDir()
// is.config.Email.Dir = tempDir

testWithIdentityServer(t, func(is *IdentityServer, cc *grpc.ClientConn) {
is.config.AdminRights.All = true
is.config.Email.Provider = "dir"
tempDir := t.TempDir()
is.config.Email.Dir = tempDir

reg := ttnpb.NewUserAccessClient(cc)

created, err := reg.CreateAPIKey(ctx, &ttnpb.CreateUserAPIKeyRequest{
UserIds: usr1.GetIds(),
Name: "api-key-name",
Rights: []ttnpb.Right{ttnpb.Right_RIGHT_USER_INFO},
}, limitedCreds)
if a.So(err, should.BeNil) && a.So(created, should.NotBeNil) {
a.So(created.Name, should.Equal, "api-key-name")
a.So(created.Rights, should.Resemble, []ttnpb.Right{ttnpb.Right_RIGHT_USER_INFO})
}

entries, err := os.ReadDir(tempDir)
if a.So(err, should.BeNil) && a.So(entries, should.HaveLength, 1) {
data, err := os.ReadFile(filepath.Join(tempDir, entries[0].Name()))
fmt.Printf("/////////////data: %v\n", string(data))
a.So(err, should.BeNil)
a.So(string(data), should.ContainSubstring, "<p>A new API key has just been created for your user")
reg := ttnpb.NewApplicationAccessClient(cc)

// API Key CRUD with different valid credentials.
for _, opts := range [][]grpc.CallOption{{adminCreds}} {
created, err := reg.CreateAPIKey(ctx, &ttnpb.CreateApplicationAPIKeyRequest{
ApplicationIds: app1.GetIds(),
Name: "api-key-name",
Rights: []ttnpb.Right{ttnpb.Right_RIGHT_APPLICATION_INFO},
}, opts...)
if a.So(err, should.BeNil) && a.So(created, should.NotBeNil) {
a.So(created.Name, should.Equal, "api-key-name")
a.So(created.Rights, should.Resemble, []ttnpb.Right{ttnpb.Right_RIGHT_APPLICATION_INFO})
}
}
})
}

0 comments on commit b33ef4f

Please sign in to comment.