Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix Ruby SDK
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Olofsson
Matrix Ruby SDK
Commits
58729e32
Verified
Commit
58729e32
authored
6 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
api: Add test and fix client discovery
parent
c5338da3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/matrix_sdk/api.rb
+2
-2
2 additions, 2 deletions
lib/matrix_sdk/api.rb
test/api_creation_test.rb
+19
-0
19 additions, 0 deletions
test/api_creation_test.rb
with
21 additions
and
2 deletions
lib/matrix_sdk/api.rb
+
2
−
2
View file @
58729e32
...
...
@@ -98,7 +98,7 @@ module MatrixSdk
else
target_uri
=
URI
(
"https://
#{
target_uri
.
target
}
:
#{
target_uri
.
port
}
"
)
end
elsif
%i[client identity]
.
include?
target
_uri
elsif
%i[client identity]
.
include?
target
# Attempt .well-known discovery
well_known
=
begin
data
=
Net
::
HTTP
.
get
(
"https://
#{
domain
}
/.well-known/matrix/client"
)
...
...
@@ -112,7 +112,7 @@ module MatrixSdk
key
=
'm.identity_server'
if
target
==
:identity
if
well_known
.
key?
(
key
)
&&
well_known
[
key
].
key?
(
'base_url'
)
uri
=
well_known
[
key
][
'base_url'
]
uri
=
URI
(
well_known
[
key
][
'base_url'
]
)
target_uri
=
uri
end
end
...
...
This diff is collapsed.
Click to expand it.
test/api_creation_test.rb
+
19
−
0
View file @
58729e32
require
'test_helper'
require
'net/http'
require
'resolv'
class
ApiTest
<
Test
::
Unit
::
TestCase
...
...
@@ -21,6 +22,24 @@ class ApiTest < Test::Unit::TestCase
assert_equal
URI
(
'https://matrix.example.com'
),
api
.
homeserver
end
def
test_client_creation_for_domain
::
Resolv
::
DNS
.
any_instance
.
expects
(
:getresource
)
.
never
::
Net
::
HTTP
.
expects
(
:get
)
.
with
(
'https://example.com/.well-known/matrix/client'
)
.
returns
(
'{"m.homeserver":{"base_url":"https://matrix.example.com"}}'
)
MatrixSdk
::
Api
.
expects
(
:new
)
.
with
(
URI
(
'https://matrix.example.com'
),
address:
'matrix.example.com'
,
port:
443
)
MatrixSdk
::
Api
.
new_for_domain
'example.com'
,
target: :client
end
def
test_server_creation_for_domain
::
Resolv
::
DNS
.
any_instance
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment