|
1 | 1 | require "./spec_helper"
|
2 | 2 |
|
3 | 3 | describe Authority do
|
4 |
| - # http_client = OAUTH_CLIENT.http_client |
5 |
| - # client = create_client |
6 |
| - # describe "Device Code Flow" do |
7 |
| - # it "gets device code" do |
8 |
| - # response = http_client.post("/device/code?client_id=#{client.client_id}") |
9 |
| - |
10 |
| - # response.status_code.should eq 201 |
11 |
| - # # Make request to "/device/code" |
12 |
| - # # Response should be |
13 |
| - # end |
14 |
| - |
15 |
| - # it "gets device token" do |
16 |
| - # end |
17 |
| - # end |
| 4 | + http_client = OAUTH_CLIENT.http_client |
| 5 | + |
| 6 | + describe "Device Code Flow" do |
| 7 | + it "gets device code" do |
| 8 | + password = Faker::Internet.password |
| 9 | + owner = create_owner(password: password) |
| 10 | + username = owner.username |
| 11 | + response = http_client.post("/device/code?client_id=#{CLIENT_ID}&scope=read") |
| 12 | + |
| 13 | + response.status_code.should eq 201 |
| 14 | + json = JSON.parse(response.body) |
| 15 | + |
| 16 | + json["verification_uri"].should eq "http://localhost:4000/activate" |
| 17 | + |
| 18 | + verification_url = json["verification_full"].as_s |
| 19 | + user_code = json["user_code"].as_s |
| 20 | + device_code = json["device_code"].as_s |
| 21 | + |
| 22 | + url = DeviceCodeFlux.flow(verification_url, username, password, user_code, "allowed") |
| 23 | + |
| 24 | + url.should eq "http://localhost:4000/activate" |
| 25 | + |
| 26 | + response = http_client.post("/device/token", form: { |
| 27 | + "grant_type" => "urn:ietf:params:oauth:grant-type:device_code", |
| 28 | + "code" => device_code, |
| 29 | + "client_id" => CLIENT_ID, |
| 30 | + |
| 31 | + }) |
| 32 | + |
| 33 | + access_token = JSON.parse(response.body) |
| 34 | + |
| 35 | + access_token["access_token"].as_s.should_not be_empty |
| 36 | + access_token["token_type"].as_s.should eq "Bearer" |
| 37 | + access_token["refresh_token"].as_s.should_not be_empty |
| 38 | + access_token["access_token"].as_s.should_not be_empty |
| 39 | + end |
| 40 | + |
| 41 | + it "gets device token" do |
| 42 | + end |
| 43 | + end |
18 | 44 | end
|
0 commit comments