Skip to content
Snippets Groups Projects
Verified Commit 58729e32 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

api: Add test and fix client discovery

parent c5338da3
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment