Skip to content

Commit

Permalink
fix a problem where refreshing access token in IDE was failing
Browse files Browse the repository at this point in the history
it is impossible to write a sensible unit test for this due to bug #7117
  • Loading branch information
radeusgd committed Apr 15, 2024
1 parent 8c3f8cb commit 7e61295
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import project.Network.HTTP.Response.Response
import project.Network.URI.URI
import project.Nothing.Nothing
import project.Panic.Panic
import project.Runtime.Context
import project.Runtime.Ref.Ref
import project.System.Environment
import project.System.File.File
Expand Down Expand Up @@ -135,7 +136,7 @@ type Refresh_Token_Data
headers = [Header.content_type "application/x-amz-json-1.1", Header.new "X-Amz-Target" "AWSCognitoIdentityProviderService.InitiateAuth"]
auth_parameters = JS_Object.from_pairs [["REFRESH_TOKEN", self.refresh_token], ["DEVICE_KEY", Nothing]]
payload = JS_Object.from_pairs [["ClientId", self.client_id], ["AuthFlow", "REFRESH_TOKEN_AUTH"], ["AuthParameters", auth_parameters]]
response = HTTP.post self.refresh_url body=(Request_Body.Json payload) headers=headers
response = Context.Output.with_enabled <| HTTP.post self.refresh_url body=(Request_Body.Json payload) headers=headers
. catch HTTP_Error error-> case error of
HTTP_Error.Status_Error status _ _ ->
# If the status code is 400-499, then most likely the reason is that the session has expired, so we ask the user to log in again.
Expand Down Expand Up @@ -179,4 +180,6 @@ file_get_required_string_field json prefix field_name = case json of
_ ->
got_type = Meta.type_of result . to_display_text
Panic.throw (Illegal_State.Error prefix+"expected `"+field_name+"` to be a string, but got "+got_type+".")
_ -> Panic.throw (Illegal_State.Error prefix+"expected an object, got "+(Meta.type_of json))
_ ->
got_type = Meta.type_of json . to_display_text
Panic.throw (Illegal_State.Error prefix+"expected an object, got "+got_type)
9 changes: 7 additions & 2 deletions test/Base_Tests/src/Network/Enso_Cloud/Cloud_Tests_Setup.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from Standard.Base import all
import Standard.Base.Errors.Illegal_State.Illegal_State
import Standard.Base.Runtime.Context

from Standard.Test import Problems
import Standard.Test.Test_Environment


Expand Down Expand Up @@ -107,8 +109,11 @@ type Cloud_Tests_Setup
enso_cloud_url = with_slash + "enso-cloud-mock/"

credentials_payload = (custom_credentials.if_nothing (Mock_Credentials.default with_slash)).to_json
tmp_cred_file = File.create_temporary_file "enso-test-credentials" ".json"
credentials_payload.write tmp_cred_file
# We need to override the Context in case the tests were running in disabled context mode
tmp_cred_file = Context.Output.with_enabled <|
tmp_cred_file = File.create_temporary_file "enso-test-credentials" ".json"
credentials_payload.write tmp_cred_file
Problems.assume_no_problems <| tmp_cred_file

Cloud_Tests_Setup.Mock (URI.from enso_cloud_url) tmp_cred_file

Expand Down

0 comments on commit 7e61295

Please sign in to comment.