-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule K8s.Conn.Auth.AzureTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
|
||
alias K8s.Conn | ||
alias K8s.Conn.Auth.Azure | ||
|
||
describe "create/2" do | ||
test "creates a Azure struct from data" do | ||
non_expired_unix_ts = DateTime.utc_now() |> DateTime.add(10, :minute) |> DateTime.to_unix() | ||
|
||
auth = %{ | ||
"auth-provider" => %{ | ||
"config" => %{ | ||
"access-token" => "xxx", | ||
"apiserver-id" => "service_id", | ||
"client-id" => "client_id", | ||
"expires-on" => "#{non_expired_unix_ts}", | ||
"refresh-token" => "yyy", | ||
"tenant-id" => "tenant" | ||
}, | ||
"name" => "azure" | ||
} | ||
} | ||
|
||
assert {:ok, | ||
%Azure{ | ||
token: "xxx" | ||
}} = Azure.create(auth, nil) | ||
end | ||
|
||
test "fails when token is expired" do | ||
expired_unix_ts = DateTime.utc_now() |> DateTime.add(-10, :minute) |> DateTime.to_unix() | ||
|
||
auth = %{ | ||
"auth-provider" => %{ | ||
"config" => %{ | ||
"access-token" => "xxx", | ||
"apiserver-id" => "service_id", | ||
"client-id" => "client_id", | ||
"expires-on" => "#{expired_unix_ts}", | ||
"refresh-token" => "yyy", | ||
"tenant-id" => "tenant" | ||
}, | ||
"name" => "azure" | ||
} | ||
} | ||
|
||
assert {:error, | ||
%K8s.Conn.Error{ | ||
message: "Azure token expired please refresh manually" | ||
}} = Azure.create(auth, nil) | ||
end | ||
end | ||
|
||
test "creates http request signing options" do | ||
provider = %Azure{ | ||
token: "xxx" | ||
} | ||
|
||
{:ok, %Conn.RequestOptions{headers: headers, ssl_options: ssl_options}} = | ||
Conn.RequestOptions.generate(provider) | ||
|
||
assert headers == [{:Authorization, "Bearer xxx"}] | ||
assert ssl_options == [] | ||
end | ||
end |