(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestGenerate(t *testing.T) { |
| 18 | t.Parallel() |
| 19 | |
| 20 | type testcase struct { |
| 21 | name string |
| 22 | params apikey.CreateParams |
| 23 | fail bool |
| 24 | } |
| 25 | |
| 26 | cases := []testcase{ |
| 27 | { |
| 28 | name: "OK", |
| 29 | params: apikey.CreateParams{ |
| 30 | UserID: uuid.New(), |
| 31 | LoginType: database.LoginTypeOIDC, |
| 32 | DefaultLifetime: time.Duration(0), |
| 33 | ExpiresAt: time.Now().Add(time.Hour), |
| 34 | LifetimeSeconds: int64(time.Hour.Seconds()), |
| 35 | TokenName: "hello", |
| 36 | RemoteAddr: "1.2.3.4", |
| 37 | Scope: database.ApiKeyScopeCoderApplicationConnect, |
| 38 | }, |
| 39 | }, |
| 40 | { |
| 41 | name: "InvalidScope", |
| 42 | params: apikey.CreateParams{ |
| 43 | UserID: uuid.New(), |
| 44 | LoginType: database.LoginTypeOIDC, |
| 45 | DefaultLifetime: time.Duration(0), |
| 46 | ExpiresAt: time.Now().Add(time.Hour), |
| 47 | LifetimeSeconds: int64(time.Hour.Seconds()), |
| 48 | TokenName: "hello", |
| 49 | RemoteAddr: "1.2.3.4", |
| 50 | Scope: database.APIKeyScope("test"), |
| 51 | }, |
| 52 | fail: true, |
| 53 | }, |
| 54 | { |
| 55 | name: "DeploymentSessionDuration", |
| 56 | params: apikey.CreateParams{ |
| 57 | UserID: uuid.New(), |
| 58 | LoginType: database.LoginTypeOIDC, |
| 59 | DefaultLifetime: time.Hour, |
| 60 | LifetimeSeconds: 0, |
| 61 | ExpiresAt: time.Time{}, |
| 62 | TokenName: "hello", |
| 63 | RemoteAddr: "1.2.3.4", |
| 64 | Scope: database.ApiKeyScopeCoderApplicationConnect, |
| 65 | }, |
| 66 | }, |
| 67 | { |
| 68 | name: "LifetimeSeconds", |
| 69 | params: apikey.CreateParams{ |
| 70 | UserID: uuid.New(), |
| 71 | LoginType: database.LoginTypeOIDC, |
| 72 | DefaultLifetime: time.Duration(0), |
| 73 | LifetimeSeconds: int64(time.Hour.Seconds()), |
| 74 | ExpiresAt: time.Time{}, |
nothing calls this directly
no test coverage detected