Skip to content

Commit cbd3d8f

Browse files
maksim-zuev-dbIsaac
andcommitted
Split the device code login acceptance test by user journey
Group the cases so that a failing test name points at the broken step: preconditions, the successful login (with a host, from a saved profile and with --scopes), unsupported hosts, an unallowed client, and missing or wrong confirmation codes. Only the nominal test prints the device code requests, because the requested scope is what it checks; the unsupported host test checks that no device authorization request is made. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent eb74444 commit cbd3d8f

27 files changed

Lines changed: 249 additions & 263 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11

22
>>> musterr [CLI] auth login --host [DATABRICKS_URL] --profile test --timeout 1s
33
Error: authorize: context deadline exceeded
4+
5+
>>> musterr [CLI] auth login --host [DATABRICKS_URL] --profile test --use-device-code --timeout 1s
6+
Using a browser on another device, visit:
7+
[DATABRICKS_URL]/device/verification
8+
9+
And enter the code:
10+
WDJB-MJHT
11+
12+
Once finished, enter the confirmation code provided in your browser.
13+
Confirmation code: Error: reading confirmation code: context deadline exceeded

‎acceptance/cmd/auth/login/timeout/script‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ sethome "./home"
55
export BROWSER="echo_browser.py"
66

77
trace musterr $CLI auth login --host $DATABRICKS_HOST --profile test --timeout 1s > /dev/null
8+
9+
# Keep stdin open without sending a confirmation code, so only --timeout ends
10+
# the device code login. The sleep must outlast the timeout, otherwise the
11+
# login fails with EOF instead.
12+
sleep 5 | DATABRICKS_CLI_DEVICE_CODE=true trace musterr $CLI auth login --host $DATABRICKS_HOST --profile test --use-device-code --timeout 1s

acceptance/cmd/auth/login/use-device-code/out.databrickscfg renamed to acceptance/cmd/auth/login/use-device-code-nominal/out.databrickscfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ auth_type = databricks-cli
99
[__settings__]
1010
default_profile = test
1111

12-
[custom-scopes]
12+
[scoped]
1313
host = [DATABRICKS_URL]
1414
workspace_id = [WORKSPACE_ID]
1515
scopes = sql

acceptance/cmd/auth/login/use-device-code-not-enabled/out.test.toml renamed to acceptance/cmd/auth/login/use-device-code-nominal/out.test.toml

File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
=== Login with a host
3+
4+
>>> [CLI] auth login --host [DATABRICKS_URL] --profile test --use-device-code
5+
Using a browser on another device, visit:
6+
[DATABRICKS_URL]/device/verification
7+
8+
And enter the code:
9+
WDJB-MJHT
10+
11+
Once finished, enter the confirmation code provided in your browser.
12+
Confirmation code: Profile test was successfully saved
13+
14+
>>> [CLI] auth token --profile test
15+
json.access_token = "oauth-token";
16+
17+
>>> [CLI] auth profiles
18+
Name Host Valid
19+
test (Default) [DATABRICKS_URL] YES
20+
21+
=== Login again with the host from the saved profile
22+
23+
>>> [CLI] auth login --profile test --use-device-code
24+
Using a browser on another device, visit:
25+
[DATABRICKS_URL]/device/verification
26+
27+
And enter the code:
28+
WDJB-MJHT
29+
30+
Once finished, enter the confirmation code provided in your browser.
31+
Confirmation code: Profile test was successfully saved
32+
33+
>>> [CLI] auth token --profile test
34+
json.access_token = "oauth-token";
35+
36+
>>> print_requests.py --oneline //oidc/v1/device/auth //oidc/v1/token
37+
{"method": "POST", "path": "/oidc/v1/device/auth", "raw_body": "client_id=databricks-cli&scope=offline_access+all-apis"}
38+
{"method": "POST", "path": "/oidc/v1/token", "raw_body": "client_id=databricks-cli&confirmation_code=FTFAQQKY&device_code=device-code-1&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code"}
39+
{"method": "POST", "path": "/oidc/v1/device/auth", "raw_body": "client_id=databricks-cli&scope=offline_access+all-apis"}
40+
{"method": "POST", "path": "/oidc/v1/token", "raw_body": "client_id=databricks-cli&confirmation_code=FTFAQQKY&device_code=device-code-2&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code"}
41+
42+
=== Login with custom scopes
43+
44+
>>> [CLI] auth login --host [DATABRICKS_URL] --profile scoped --use-device-code --scopes sql
45+
Using a browser on another device, visit:
46+
[DATABRICKS_URL]/device/verification
47+
48+
And enter the code:
49+
WDJB-MJHT
50+
51+
Once finished, enter the confirmation code provided in your browser.
52+
Confirmation code: Profile scoped was successfully saved
53+
54+
>>> print_requests.py --oneline //oidc/v1/device/auth //oidc/v1/token
55+
{"method": "POST", "path": "/oidc/v1/device/auth", "raw_body": "client_id=databricks-cli&scope=offline_access+sql"}
56+
{"method": "POST", "path": "/oidc/v1/token", "raw_body": "client_id=databricks-cli&confirmation_code=FTFAQQKY&device_code=device-code-3&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code"}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sethome "./home"
2+
export DATABRICKS_CLI_DEVICE_CODE=true
3+
4+
title "Login with a host\n"
5+
printf "FTFA-QQKY\n" | trace $CLI auth login --host $DATABRICKS_HOST --profile test --use-device-code
6+
trace $CLI auth token --profile test | gron.py | grep access_token
7+
trace $CLI auth profiles
8+
9+
title "Login again with the host from the saved profile\n"
10+
printf "FTFA-QQKY\n" | trace $CLI auth login --profile test --use-device-code
11+
trace $CLI auth token --profile test | gron.py | grep access_token
12+
trace print_requests.py --oneline //oidc/v1/device/auth //oidc/v1/token
13+
14+
# The token gets the scopes requested at device authorization, so --scopes is
15+
# sent there and not with the token request.
16+
title "Login with custom scopes\n"
17+
printf "FTFA-QQKY\n" | trace $CLI auth login --host $DATABRICKS_HOST --profile scoped --use-device-code --scopes sql
18+
trace print_requests.py --oneline //oidc/v1/device/auth //oidc/v1/token
19+
20+
# Track the .databrickscfg file that was created to surface changes.
21+
mv "./home/.databrickscfg" "./out.databrickscfg"

acceptance/cmd/auth/login/use-device-code-unified-host/test.toml renamed to acceptance/cmd/auth/login/use-device-code-nominal/test.toml

File renamed without changes.

‎acceptance/cmd/auth/login/use-device-code-not-enabled/output.txt‎

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

‎acceptance/cmd/auth/login/use-device-code-not-enabled/script‎

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[scoped]
2+
host = $DATABRICKS_HOST
3+
auth_type = databricks-cli
4+
resources = https://resource.test

0 commit comments

Comments
 (0)