Skip to content

Commit 7896f96

Browse files
authored
refactor(server): extract the device authorization endpoints into a package (#4906)
Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com>
1 parent cf4ab8b commit 7896f96

10 files changed

Lines changed: 453 additions & 407 deletions

File tree

server/device/device.go

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

server/device/device_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package device
2+
3+
import (
4+
"net/url"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestGetDeviceVerificationURI(t *testing.T) {
11+
u, err := url.Parse("https://dex.example.com/non-root-path")
12+
require.NoError(t, err)
13+
14+
h := &Handler{IssuerURL: *u}
15+
require.Equal(t, "/non-root-path/device/auth/verify_code", h.getDeviceVerificationURI())
16+
}

server/device_authorize.go

Lines changed: 0 additions & 238 deletions
This file was deleted.

server/device_authorize_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,10 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/dexidp/dex/server/device"
1516
"github.com/dexidp/dex/storage"
1617
)
1718

18-
func TestDeviceVerificationURI(t *testing.T) {
19-
t0 := time.Now()
20-
21-
now := func() time.Time { return t0 }
22-
// Setup a dex server.
23-
httpServer, s := newTestServer(t, func(c *Config) {
24-
c.Issuer += "/non-root-path"
25-
c.Now = now
26-
})
27-
defer httpServer.Close()
28-
29-
u, err := url.Parse(s.issuerURL.String())
30-
if err != nil {
31-
t.Fatalf("Could not parse issuer URL %v", err)
32-
}
33-
u.Path = path.Join(u.Path, "/device/auth/verify_code")
34-
35-
uri := s.getDeviceVerificationURI()
36-
if uri != u.Path {
37-
t.Errorf("Invalid verification URI. Expected %v got %v", u.Path, uri)
38-
}
39-
}
40-
4119
func TestHandleDeviceCode(t *testing.T) {
4220
t0 := time.Now()
4321

@@ -135,7 +113,7 @@ func TestHandleDeviceCode(t *testing.T) {
135113
t.Errorf("Could read token response %v", err)
136114
}
137115
if tc.expectedResponseCode == http.StatusOK {
138-
var resp deviceCodeResponse
116+
var resp device.DeviceCodeResponse
139117
if err := json.Unmarshal(body, &resp); err != nil {
140118
t.Errorf("Unexpected Device Code Response Format %v", string(body))
141119
}

0 commit comments

Comments
 (0)