(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func 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 |
nothing calls this directly
no test coverage detected