{"action":"created","comment":{"url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/comments/39660469","id":39660469,"diff_hunk":"@@ -628,6 +628,48 @@ fn test_alpn_server_advertise_multiple() {\n     assert_eq!(b\"spdy/3.1\", stream.get_selected_alpn_protocol().unwrap());\n }\n \n+/// Test that Servers supporting ALPN don't report a protocol when none of their protocols match\n+/// the client's reported protocol.\n+#[test]\n+#[cfg(feature = \"alpn\")]\n+fn test_alpn_server_select_none() {\n+    let localhost = \"127.0.0.1:15422\";\n+    let listener = TcpListener::bind(localhost).unwrap();\n+    // We create a different context instance for the server...\n+    let listener_ctx = {\n+        let mut ctx = SslContext::new(Sslv23).unwrap();\n+        ctx.set_verify(SSL_VERIFY_PEER, None);\n+        ctx.set_alpn_protocols(&[b\"http/1.1\", b\"spdy/3.1\"]);\n+        assert!(ctx.set_certificate_file(\n+                &Path::new(\"test/cert.pem\"), X509FileType::PEM).is_ok());\n+        ctx.set_private_key_file(\n+                &Path::new(\"test/key.pem\"), X509FileType::PEM).unwrap();\n+        ctx\n+    };\n+    // Have the listener wait on the connection in a different thread.\n+    thread::spawn(move || {\n+        let (stream, _) = listener.accept().unwrap();\n+        let _ = SslStream::accept(&listener_ctx, stream).unwrap();\n+    });\n+\n+    let mut ctx = SslContext::new(Sslv23).unwrap();\n+    ctx.set_verify(SSL_VERIFY_PEER, None);\n+    ctx.set_alpn_protocols(&[b\"http/2\"]);\n+    match ctx.set_CA_file(&Path::new(\"test/cert.pem\")) {\n+        Ok(_) => {}\n+        Err(err) => panic!(\"Unexpected error {:?}\", err)\n+    }\n+    // Now connect to the socket and make sure the protocol negotiation works...\n+    let stream = TcpStream::connect(localhost).unwrap();\n+    let stream = match SslStream::new(&ctx, stream) {\n+        Ok(stream) => stream,\n+        Err(err) => panic!(\"Expected success, got {:?}\", err)\n+    };\n+    // SPDY is selected since that's the only thing the client supports.","path":"openssl/src/ssl/tests.rs","position":null,"original_position":68,"commit_id":"4c28eb706e06463f1e00e143d2d52d8e23827c1b","original_commit_id":"b604c17c464caf049ef30e05f077a8156e061167","user":{"login":"jmesmon","id":103437,"avatar_url":"https://avatars.githubusercontent.com/u/103437?v=3","gravatar_id":"","url":"https://api.github.com/users/jmesmon","html_url":"https://github.com/jmesmon","followers_url":"https://api.github.com/users/jmesmon/followers","following_url":"https://api.github.com/users/jmesmon/following{/other_user}","gists_url":"https://api.github.com/users/jmesmon/gists{/gist_id}","starred_url":"https://api.github.com/users/jmesmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmesmon/subscriptions","organizations_url":"https://api.github.com/users/jmesmon/orgs","repos_url":"https://api.github.com/users/jmesmon/repos","events_url":"https://api.github.com/users/jmesmon/events{/privacy}","received_events_url":"https://api.github.com/users/jmesmon/received_events","type":"User","site_admin":false},"body":"whoops. commit updated to fix.","created_at":"2015-09-16T17:35:45Z","updated_at":"2015-09-16T17:35:45Z","html_url":"https://github.com/sfackler/rust-openssl/pull/266#discussion_r39660469","pull_request_url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266","_links":{"self":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/comments/39660469"},"html":{"href":"https://github.com/sfackler/rust-openssl/pull/266#discussion_r39660469"},"pull_request":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266"}}},"pull_request":{"url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266","id":43927630,"html_url":"https://github.com/sfackler/rust-openssl/pull/266","diff_url":"https://github.com/sfackler/rust-openssl/pull/266.diff","patch_url":"https://github.com/sfackler/rust-openssl/pull/266.patch","issue_url":"https://api.github.com/repos/sfackler/rust-openssl/issues/266","number":266,"state":"open","locked":false,"title":"ssl/npn+alpn: adjust protocol selection to fail if no protocols match","user":{"login":"jmesmon","id":103437,"avatar_url":"https://avatars.githubusercontent.com/u/103437?v=3","gravatar_id":"","url":"https://api.github.com/users/jmesmon","html_url":"https://github.com/jmesmon","followers_url":"https://api.github.com/users/jmesmon/followers","following_url":"https://api.github.com/users/jmesmon/following{/other_user}","gists_url":"https://api.github.com/users/jmesmon/gists{/gist_id}","starred_url":"https://api.github.com/users/jmesmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmesmon/subscriptions","organizations_url":"https://api.github.com/users/jmesmon/orgs","repos_url":"https://api.github.com/users/jmesmon/repos","events_url":"https://api.github.com/users/jmesmon/events{/privacy}","received_events_url":"https://api.github.com/users/jmesmon/received_events","type":"User","site_admin":false},"body":"ssl/npn+alpn: adjust protocol selection to fail if no protocols match\r\nThe current behavior causes a server written using rust-openssl to (if\r\nit cannot negotiate a protocol) fallback to the first protocol it has\r\navaliable.\r\n\r\nThis makes it impossible to detect protocol mismatches.\r\n\r\nThis updates our selection to be more similar to how openssl's\r\ns_server behaves: non-matching protocols are not supplied with a\r\nfallback.\r\n\r\nNote that some setups may actually want a fallback protocol supplied\r\nvia ALPN. To support those cases, we should consider adding a generic\r\ncallback that allows protocol selection to be entirely controlled by\r\nthe programmer.\r\n\r\nFor the purposes of having a sane default, however, not supplying a\r\ndefault (and mimicing s_server's behavior) is the best choice.\r\n","created_at":"2015-09-01T21:15:04Z","updated_at":"2015-09-16T17:35:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"546332c94403eafd5f1175dee744cee55ce9150c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266/commits","review_comments_url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266/comments","review_comment_url":"https://api.github.com/repos/sfackler/rust-openssl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sfackler/rust-openssl/issues/266/comments","statuses_url":"https://api.github.com/repos/sfackler/rust-openssl/statuses/4c28eb706e06463f1e00e143d2d52d8e23827c1b","head":{"label":"jmesmon:alpn","ref":"alpn","sha":"4c28eb706e06463f1e00e143d2d52d8e23827c1b","user":{"login":"jmesmon","id":103437,"avatar_url":"https://avatars.githubusercontent.com/u/103437?v=3","gravatar_id":"","url":"https://api.github.com/users/jmesmon","html_url":"https://github.com/jmesmon","followers_url":"https://api.github.com/users/jmesmon/followers","following_url":"https://api.github.com/users/jmesmon/following{/other_user}","gists_url":"https://api.github.com/users/jmesmon/gists{/gist_id}","starred_url":"https://api.github.com/users/jmesmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmesmon/subscriptions","organizations_url":"https://api.github.com/users/jmesmon/orgs","repos_url":"https://api.github.com/users/jmesmon/repos","events_url":"https://api.github.com/users/jmesmon/events{/privacy}","received_events_url":"https://api.github.com/users/jmesmon/received_events","type":"User","site_admin":false},"repo":{"id":24380283,"name":"rust-openssl","full_name":"jmesmon/rust-openssl","owner":{"login":"jmesmon","id":103437,"avatar_url":"https://avatars.githubusercontent.com/u/103437?v=3","gravatar_id":"","url":"https://api.github.com/users/jmesmon","html_url":"https://github.com/jmesmon","followers_url":"https://api.github.com/users/jmesmon/followers","following_url":"https://api.github.com/users/jmesmon/following{/other_user}","gists_url":"https://api.github.com/users/jmesmon/gists{/gist_id}","starred_url":"https://api.github.com/users/jmesmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmesmon/subscriptions","organizations_url":"https://api.github.com/users/jmesmon/orgs","repos_url":"https://api.github.com/users/jmesmon/repos","events_url":"https://api.github.com/users/jmesmon/events{/privacy}","received_events_url":"https://api.github.com/users/jmesmon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmesmon/rust-openssl","description":"OpenSSL bindings for Rust","fork":true,"url":"https://api.github.com/repos/jmesmon/rust-openssl","forks_url":"https://api.github.com/repos/jmesmon/rust-openssl/forks","keys_url":"https://api.github.com/repos/jmesmon/rust-openssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmesmon/rust-openssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmesmon/rust-openssl/teams","hooks_url":"https://api.github.com/repos/jmesmon/rust-openssl/hooks","issue_events_url":"https://api.github.com/repos/jmesmon/rust-openssl/issues/events{/number}","events_url":"https://api.github.com/repos/jmesmon/rust-openssl/events","assignees_url":"https://api.github.com/repos/jmesmon/rust-openssl/assignees{/user}","branches_url":"https://api.github.com/repos/jmesmon/rust-openssl/branches{/branch}","tags_url":"https://api.github.com/repos/jmesmon/rust-openssl/tags","blobs_url":"https://api.github.com/repos/jmesmon/rust-openssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmesmon/rust-openssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmesmon/rust-openssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmesmon/rust-openssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmesmon/rust-openssl/statuses/{sha}","languages_url":"https://api.github.com/repos/jmesmon/rust-openssl/languages","stargazers_url":"https://api.github.com/repos/jmesmon/rust-openssl/stargazers","contributors_url":"https://api.github.com/repos/jmesmon/rust-openssl/contributors","subscribers_url":"https://api.github.com/repos/jmesmon/rust-openssl/subscribers","subscription_url":"https://api.github.com/repos/jmesmon/rust-openssl/subscription","commits_url":"https://api.github.com/repos/jmesmon/rust-openssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmesmon/rust-openssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmesmon/rust-openssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmesmon/rust-openssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmesmon/rust-openssl/contents/{+path}","compare_url":"https://api.github.com/repos/jmesmon/rust-openssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmesmon/rust-openssl/merges","archive_url":"https://api.github.com/repos/jmesmon/rust-openssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmesmon/rust-openssl/downloads","issues_url":"https://api.github.com/repos/jmesmon/rust-openssl/issues{/number}","pulls_url":"https://api.github.com/repos/jmesmon/rust-openssl/pulls{/number}","milestones_url":"https://api.github.com/repos/jmesmon/rust-openssl/milestones{/number}","notifications_url":"https://api.github.com/repos/jmesmon/rust-openssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmesmon/rust-openssl/labels{/name}","releases_url":"https://api.github.com/repos/jmesmon/rust-openssl/releases{/id}","created_at":"2014-09-23T16:44:56Z","updated_at":"2014-11-19T21:24:43Z","pushed_at":"2015-09-16T17:35:25Z","git_url":"git://github.com/jmesmon/rust-openssl.git","ssh_url":"git@github.com:jmesmon/rust-openssl.git","clone_url":"https://github.com/jmesmon/rust-openssl.git","svn_url":"https://github.com/jmesmon/rust-openssl","homepage":"","size":1185,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sfackler:master","ref":"master","sha":"1c3f04138fcf7efd28d3c4b83327b8333944d01b","user":{"login":"sfackler","id":1455697,"avatar_url":"https://avatars.githubusercontent.com/u/1455697?v=3","gravatar_id":"","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"repo":{"id":15500883,"name":"rust-openssl","full_name":"sfackler/rust-openssl","owner":{"login":"sfackler","id":1455697,"avatar_url":"https://avatars.githubusercontent.com/u/1455697?v=3","gravatar_id":"","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sfackler/rust-openssl","description":"OpenSSL bindings for Rust","fork":false,"url":"https://api.github.com/repos/sfackler/rust-openssl","forks_url":"https://api.github.com/repos/sfackler/rust-openssl/forks","keys_url":"https://api.github.com/repos/sfackler/rust-openssl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sfackler/rust-openssl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sfackler/rust-openssl/teams","hooks_url":"https://api.github.com/repos/sfackler/rust-openssl/hooks","issue_events_url":"https://api.github.com/repos/sfackler/rust-openssl/issues/events{/number}","events_url":"https://api.github.com/repos/sfackler/rust-openssl/events","assignees_url":"https://api.github.com/repos/sfackler/rust-openssl/assignees{/user}","branches_url":"https://api.github.com/repos/sfackler/rust-openssl/branches{/branch}","tags_url":"https://api.github.com/repos/sfackler/rust-openssl/tags","blobs_url":"https://api.github.com/repos/sfackler/rust-openssl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sfackler/rust-openssl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sfackler/rust-openssl/git/refs{/sha}","trees_url":"https://api.github.com/repos/sfackler/rust-openssl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sfackler/rust-openssl/statuses/{sha}","languages_url":"https://api.github.com/repos/sfackler/rust-openssl/languages","stargazers_url":"https://api.github.com/repos/sfackler/rust-openssl/stargazers","contributors_url":"https://api.github.com/repos/sfackler/rust-openssl/contributors","subscribers_url":"https://api.github.com/repos/sfackler/rust-openssl/subscribers","subscription_url":"https://api.github.com/repos/sfackler/rust-openssl/subscription","commits_url":"https://api.github.com/repos/sfackler/rust-openssl/commits{/sha}","git_commits_url":"https://api.github.com/repos/sfackler/rust-openssl/git/commits{/sha}","comments_url":"https://api.github.com/repos/sfackler/rust-openssl/comments{/number}","issue_comment_url":"https://api.github.com/repos/sfackler/rust-openssl/issues/comments{/number}","contents_url":"https://api.github.com/repos/sfackler/rust-openssl/contents/{+path}","compare_url":"https://api.github.com/repos/sfackler/rust-openssl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sfackler/rust-openssl/merges","archive_url":"https://api.github.com/repos/sfackler/rust-openssl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sfackler/rust-openssl/downloads","issues_url":"https://api.github.com/repos/sfackler/rust-openssl/issues{/number}","pulls_url":"https://api.github.com/repos/sfackler/rust-openssl/pulls{/number}","milestones_url":"https://api.github.com/repos/sfackler/rust-openssl/milestones{/number}","notifications_url":"https://api.github.com/repos/sfackler/rust-openssl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sfackler/rust-openssl/labels{/name}","releases_url":"https://api.github.com/repos/sfackler/rust-openssl/releases{/id}","created_at":"2013-12-28T23:56:50Z","updated_at":"2015-09-13T12:35:40Z","pushed_at":"2015-09-16T17:35:25Z","git_url":"git://github.com/sfackler/rust-openssl.git","ssh_url":"git@github.com:sfackler/rust-openssl.git","clone_url":"https://github.com/sfackler/rust-openssl.git","svn_url":"https://github.com/sfackler/rust-openssl","homepage":"","size":8225,"stargazers_count":112,"watchers_count":112,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":87,"mirror_url":null,"open_issues_count":36,"forks":87,"open_issues":36,"watchers":112,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266"},"html":{"href":"https://github.com/sfackler/rust-openssl/pull/266"},"issue":{"href":"https://api.github.com/repos/sfackler/rust-openssl/issues/266"},"comments":{"href":"https://api.github.com/repos/sfackler/rust-openssl/issues/266/comments"},"review_comments":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266/comments"},"review_comment":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sfackler/rust-openssl/pulls/266/commits"},"statuses":{"href":"https://api.github.com/repos/sfackler/rust-openssl/statuses/4c28eb706e06463f1e00e143d2d52d8e23827c1b"}}}}