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

api: More fixes for discovery

parent 968b56e3
Branches
Tags
No related merge requests found
## 2.1.2 - **Unreleased**
- Adds method for reading complete member lists for rooms, improves the CS spec adherence
- Adds test for state events
- Fixes state event handler for rooms not actually passing events
- Fixes Api#new_for_domain using a faulty URI in certain cases
## 2.1.1 - 2020-08-21
......
......@@ -115,10 +115,10 @@ module MatrixSdk
if target_uri.nil?
# Attempt .well-known discovery for server-to-server
well_known = begin
uri = URI("https://#{domain}/.well-known/matrix/server")
logger.debug "Trying #{uri}..."
data = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 5, read_timeout: 5, write_timeout: 5) do |http|
http.get(uri.path).body
wk_uri = URI("https://#{domain}/.well-known/matrix/server")
logger.debug "Trying #{wk_uri}..."
data = Net::HTTP.start(wk_uri.host, wk_uri.port, use_ssl: true, open_timeout: 5, read_timeout: 5, write_timeout: 5) do |http|
http.get(wk_uri.path).body
end
JSON.parse(data)
rescue StandardError => e
......@@ -133,10 +133,10 @@ module MatrixSdk
elsif %i[client identity].include? target
# Attempt .well-known discovery
well_known = begin
uri = URI("https://#{domain}/.well-known/matrix/client")
logger.debug "Trying #{uri}..."
data = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 5, read_timeout: 5, write_timeout: 5) do |http|
http.get(uri.path).body
wk_uri = URI("https://#{domain}/.well-known/matrix/client")
logger.debug "Trying #{wk_uri}..."
data = Net::HTTP.start(wk_uri.host, wk_uri.port, use_ssl: true, open_timeout: 5, read_timeout: 5, write_timeout: 5) do |http|
http.get(wk_uri.path).body
end
data = JSON.parse(data)
rescue StandardError => e
......
......@@ -66,9 +66,10 @@ class ApiTest < Test::Unit::TestCase
.never
::Net::HTTP
.any_instance
.expects(:get)
.with('https://example.com/.well-known/matrix/client')
.returns('{"m.homeserver":{"base_url":"https://matrix.example.com"}}')
.with('/.well-known/matrix/client')
.returns(OpenStruct.new(body: '{"m.homeserver":{"base_url":"https://matrix.example.com"}}'))
MatrixSdk::Api
.expects(:new)
......@@ -83,6 +84,11 @@ class ApiTest < Test::Unit::TestCase
.expects(:getresource)
.returns(Resolv::DNS::Resource::IN::SRV.new(10, 1, 443, 'matrix.example.com'))
::Net::HTTP
.any_instance
.expects(:get)
.never
MatrixSdk::Api
.expects(:new)
.with(URI('https://example.com'), address: 'matrix.example.com', port: 443)
......@@ -96,6 +102,13 @@ class ApiTest < Test::Unit::TestCase
.expects(:getresource)
.raises(::Resolv::ResolvError)
::Net::HTTP
.any_instance
.expects(:get)
.with('/.well-known/matrix/server')
.once
.raises(StandardError)
MatrixSdk::Api
.expects(:new)
.with(URI('https://example.com'), address: 'example.com', port: 8448)
......@@ -118,12 +131,16 @@ class ApiTest < Test::Unit::TestCase
.raises(::Resolv::ResolvError)
::Net::HTTP
.any_instance
.expects(:get)
.with('https://example.com/.well-known/matrix/server')
.with('/.well-known/matrix/server')
.once
.raises(StandardError)
::Net::HTTP
.any_instance
.expects(:get)
.with('https://example.com/.well-known/matrix/client')
.with('/.well-known/matrix/client')
.once
.raises(StandardError)
api = MatrixSdk::Api.new_for_domain('example.com', target: :server)
......
......@@ -61,13 +61,16 @@ class ClientTest < Test::Unit::TestCase
def test_events
cl = MatrixSdk::Client.new 'https://example.com'
room = cl.ensure_room '!726s6s6q:example.com'
cl.instance_variable_get(:@on_presence_event).expects(:fire).once
cl.instance_variable_get(:@on_invite_event).expects(:fire).once
cl.instance_variable_get(:@on_leave_event).expects(:fire).once
cl.instance_variable_get(:@on_event).expects(:fire).twice
cl.instance_variable_get(:@on_ephemeral_event).expects(:fire).once
room.instance_variable_get(:@on_state_event).expects(:fire).twice
room.instance_variable_get(:@on_event).expects(:fire).twice
room.instance_variable_get(:@on_ephemeral_event).expects(:fire).once
response = JSON.parse(open('test/fixtures/sync_response.json').read, symbolize_names: true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment