MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestUserCreate

Function TestUserCreate

pkg/identityserver/user_registry_test.go:101–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestUserCreate(t *testing.T) {
102 t.Parallel()
103
104 p := &storetest.Population{}
105
106 a, ctx := test.New(t)
107
108 req := &ttnpb.CreateUserRequest{
109 User: &ttnpb.User{
110 Ids: &ttnpb.UserIdentifiers{UserId: "test-user-id"},
111 PrimaryEmailAddress: "test-user@example.com",
112 Password: "test password",
113 },
114 }
115
116 testWithIdentityServer(t, func(is *IdentityServer, cc *grpc.ClientConn) {
117 reg := ttnpb.NewUserRegistryClient(cc)
118
119 is.config.UserRegistration.Enabled = false
120
121 _, err := reg.Create(ctx, req)
122 if a.So(err, should.NotBeNil) {
123 a.So(errors.Resemble(err, errUserRegistrationDisabled), should.BeTrue)
124 }
125
126 is.config.UserRegistration.Enabled = true
127 is.config.UserRegistration.Invitation.Required = true
128
129 t.Run("InvitationRequired", func(t *testing.T) { // nolint:paralleltest
130 t.Run("WithoutInvitation", func(t *testing.T) { // nolint:paralleltest
131 a, ctx := test.New(t)
132 _, err = reg.Create(ctx, req)
133 if a.So(err, should.NotBeNil) {
134 a.So(errors.Resemble(err, errInvitationTokenRequired), should.BeTrue)
135 }
136 })
137 t.Run("WithInvitation", func(t *testing.T) { // nolint:paralleltest
138 t.Run("Expired", func(t *testing.T) { // nolint:paralleltest
139 a, ctx := test.New(t)
140 req := &ttnpb.CreateUserRequest{
141 User: &ttnpb.User{
142 Ids: &ttnpb.UserIdentifiers{UserId: "test-invitation-expired"},
143 PrimaryEmailAddress: "test-invitation-expired@example.com",
144 Password: "test-invitation-expired",
145 },
146 InvitationToken: "TOKEN_EXPIRED",
147 }
148 _, err := is.store.CreateInvitation(
149 ctx, &ttnpb.Invitation{
150 Email: req.User.PrimaryEmailAddress,
151 Token: "TOKEN_EXPIRED", ExpiresAt: timestamppb.New(time.Now().Add(-5 * time.Minute)),
152 },
153 )
154 a.So(err, should.BeNil)
155 _, err = reg.Create(ctx, req)
156 a.So(errors.IsFailedPrecondition(err), should.BeTrue)
157 })
158 t.Run("Valid token", func(t *testing.T) { // nolint:paralleltest

Callers

nothing calls this directly

Calls 14

CreateMethod · 0.95
GetUserMethod · 0.95
NewFunction · 0.92
NewUserRegistryClientFunction · 0.92
ResembleFunction · 0.92
IsFailedPreconditionFunction · 0.92
testWithIdentityServerFunction · 0.85
withPrivateTestDatabaseFunction · 0.85
RunMethod · 0.65
CreateInvitationMethod · 0.65
NewMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected