File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
49
49
import { DataCache } from "../data-cache" ;
50
50
import { TransactionalDBImpl } from "./transactional-db-impl" ;
51
51
import { TypeORM } from "./typeorm" ;
52
+ import { ApplicationError , ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
52
53
53
54
// OAuth token expiry
54
55
const tokenExpiryInFuture = new DateInterval ( "7d" ) ;
@@ -132,6 +133,9 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
132
133
}
133
134
134
135
public async findUserById ( id : string ) : Promise < MaybeUser > {
136
+ if ( ! id || id . trim ( ) === "" ) {
137
+ throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Cannot find user without id" ) ;
138
+ }
135
139
return this . cache . get ( getUserCacheKey ( id ) , async ( ) => {
136
140
const userRepo = await this . getUserRepo ( ) ;
137
141
const result = await userRepo . findOne ( id ) ;
Original file line number Diff line number Diff line change @@ -97,6 +97,36 @@ class UserDBSpec {
97
97
expect ( dbResult ) . to . deep . include ( user ) ;
98
98
}
99
99
100
+ @test ( timeout ( 10000 ) )
101
+ public async findUserById ( ) {
102
+ const user = await this . db . newUser ( ) ;
103
+ user . identities . push ( this . IDENTITY1 ) ;
104
+ await this . db . storeUser ( user ) ;
105
+
106
+ const foundUser = await this . db . findUserById ( user . id ) ;
107
+ expect ( foundUser ! . id ) . to . eq ( user . id ) ;
108
+ }
109
+
110
+ @test ( timeout ( 10000 ) )
111
+ public async findUserById_undefined ( ) {
112
+ const user = await this . db . newUser ( ) ;
113
+ user . identities . push ( this . IDENTITY1 ) ;
114
+ await this . db . storeUser ( user ) ;
115
+
116
+ try {
117
+ await this . db . findUserById ( undefined ! ) ;
118
+ expect . fail ( "Should have failed" ) ;
119
+ } catch ( error ) {
120
+ expect ( error . code ) . to . eq ( 400 ) ;
121
+ }
122
+ try {
123
+ await this . db . findUserById ( "" ) ;
124
+ expect . fail ( "Should have failed" ) ;
125
+ } catch ( error ) {
126
+ expect ( error . code ) . to . eq ( 400 ) ;
127
+ }
128
+ }
129
+
100
130
@test ( timeout ( 10000 ) )
101
131
public async findUsersByEmail_multiple_users_identities ( ) {
102
132
let user1 = await this . db . newUser ( ) ;
You can’t perform that action at this time.
0 commit comments