mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
Fix etcd device requests (#3119)
Signed-off-by: MM53 <28218664+MM53@users.noreply.github.com>
This commit is contained in:
@@ -16,12 +16,16 @@ jobs:
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:10.8
|
||||
env:
|
||||
TZ: UTC
|
||||
ports:
|
||||
- 5432
|
||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
||||
|
||||
postgres-ent:
|
||||
image: postgres:10.8
|
||||
env:
|
||||
TZ: UTC
|
||||
ports:
|
||||
- 5432
|
||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
jose "gopkg.in/square/go-jose.v2"
|
||||
|
||||
@@ -980,7 +981,7 @@ func testDeviceRequestCRUD(t *testing.T, s storage.Storage) {
|
||||
ClientID: "client1",
|
||||
ClientSecret: "secret1",
|
||||
Scopes: []string{"openid", "email"},
|
||||
Expiry: neverExpire,
|
||||
Expiry: neverExpire.Round(time.Second),
|
||||
}
|
||||
|
||||
if err := s.CreateDeviceRequest(d1); err != nil {
|
||||
@@ -991,6 +992,13 @@ func testDeviceRequestCRUD(t *testing.T, s storage.Storage) {
|
||||
err := s.CreateDeviceRequest(d1)
|
||||
mustBeErrAlreadyExists(t, "device request", err)
|
||||
|
||||
got, err := s.GetDeviceRequest(d1.UserCode)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get device request: %v", err)
|
||||
}
|
||||
|
||||
require.Equal(t, d1, got)
|
||||
|
||||
// No manual deletes for device requests, will be handled by garbage collection routines
|
||||
// see testGC
|
||||
}
|
||||
|
||||
@@ -577,8 +577,11 @@ func (c *conn) CreateDeviceRequest(d storage.DeviceRequest) error {
|
||||
func (c *conn) GetDeviceRequest(userCode string) (r storage.DeviceRequest, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
|
||||
defer cancel()
|
||||
err = c.getKey(ctx, keyID(deviceRequestPrefix, userCode), &r)
|
||||
return r, err
|
||||
var dr DeviceRequest
|
||||
if err = c.getKey(ctx, keyID(deviceRequestPrefix, userCode), &dr); err == nil {
|
||||
r = toStorageDeviceRequest(dr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *conn) listDeviceRequests(ctx context.Context) (requests []DeviceRequest, err error) {
|
||||
|
||||
@@ -277,6 +277,17 @@ func fromStorageDeviceRequest(d storage.DeviceRequest) DeviceRequest {
|
||||
}
|
||||
}
|
||||
|
||||
func toStorageDeviceRequest(d DeviceRequest) storage.DeviceRequest {
|
||||
return storage.DeviceRequest{
|
||||
UserCode: d.UserCode,
|
||||
DeviceCode: d.DeviceCode,
|
||||
ClientID: d.ClientID,
|
||||
ClientSecret: d.ClientSecret,
|
||||
Scopes: d.Scopes,
|
||||
Expiry: d.Expiry,
|
||||
}
|
||||
}
|
||||
|
||||
// DeviceToken is a mirrored struct from storage with JSON struct tags
|
||||
type DeviceToken struct {
|
||||
DeviceCode string `json:"device_code"`
|
||||
|
||||
Reference in New Issue
Block a user