diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-27 15:56:57 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-27 15:56:57 +0400 |
commit | 51068952db8fa263f576e49ee7d2ce1dcc89898a (patch) | |
tree | 69da0c13194eac465950c48ab95cf83d988571dc | |
parent | 8b067e765c249beff379d4d416cd7dff702b51fb (diff) |
Check uri scheme before making RPC
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/UDP.hs | 7 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 13 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs index 160397dd..0cb8e95e 100644 --- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs +++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs | |||
@@ -212,6 +212,9 @@ data RpcException | |||
212 | -- | Unable to lookup hostname; | 212 | -- | Unable to lookup hostname; |
213 | | HostLookupFailed | 213 | | HostLookupFailed |
214 | 214 | ||
215 | -- | Expecting 'udp:', but some other scheme provided. | ||
216 | | UnrecognizedScheme String | ||
217 | |||
215 | -- | Tracker exists but not responding for specific number of seconds. | 218 | -- | Tracker exists but not responding for specific number of seconds. |
216 | | TimeoutExpired Int | 219 | | TimeoutExpired Int |
217 | 220 | ||
@@ -250,7 +253,9 @@ resolveURI _ = throwIO HostUnknown | |||
250 | 253 | ||
251 | -- TODO caching? | 254 | -- TODO caching? |
252 | getTrackerAddr :: Manager -> URI -> IO SockAddr | 255 | getTrackerAddr :: Manager -> URI -> IO SockAddr |
253 | getTrackerAddr _ = resolveURI | 256 | getTrackerAddr _ uri |
257 | | uriScheme uri == "udp:" = resolveURI uri | ||
258 | | otherwise = throwIO (UnrecognizedScheme (uriScheme uri)) | ||
254 | 259 | ||
255 | {----------------------------------------------------------------------- | 260 | {----------------------------------------------------------------------- |
256 | Tokens | 261 | Tokens |
diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs index 598b2866..8a1ffc01 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | |||
@@ -97,6 +97,19 @@ spec = parallel $ do | |||
97 | scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException | 97 | scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException |
98 | 98 | ||
99 | describe "RPC" $ do | 99 | describe "RPC" $ do |
100 | describe "announce" $ do | ||
101 | it "must fail on bad scheme" $ do | ||
102 | withManager rpcOpts $ \ mgr -> do | ||
103 | q <- arbitrarySample | ||
104 | announce mgr "magnet://a.com" q | ||
105 | `shouldThrow` (== UnrecognizedScheme "magnet:") | ||
106 | |||
107 | describe "scrape" $ do | ||
108 | it "must fail on bad scheme" $ do | ||
109 | withManager rpcOpts $ \ mgr -> do | ||
110 | scrape mgr "magnet://a.com" [] | ||
111 | `shouldThrow` (== UnrecognizedScheme "magnet:") | ||
112 | |||
100 | forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> | 113 | forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> |
101 | context trackerName $ do | 114 | context trackerName $ do |
102 | 115 | ||