mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
Deploying to gh-pages from @ ce92f0036f
🚀
This commit is contained in:
parent
e71133ad8d
commit
1f62eadff4
@ -4,7 +4,7 @@
|
||||
</nav>
|
||||
<nav class="sidebar"><a class="sidebar-logo" href="../../actix_web_httpauth/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div>
|
||||
</a><h2 class="location"><a href="#">Module middleware</a></h2><div class="sidebar-elems"><section><div class="block"><ul><li><a href="#structs">Structs</a></li></ul></div></section><div id="sidebar-vars" data-name="middleware" data-ty="mod" data-relpath="./"></div><script defer src="./sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../actix_web_httpauth/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
||||
<h1 class="fqn"><span class="in-band">Module <a href="../index.html">actix_web_httpauth</a>::<wbr><a class="mod" href="#">middleware</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../src/actix_web_httpauth/middleware.rs.html#1-357">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>HTTP Authentication middleware.</p>
|
||||
<h1 class="fqn"><span class="in-band">Module <a href="../index.html">actix_web_httpauth</a>::<wbr><a class="mod" href="#">middleware</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../src/actix_web_httpauth/middleware.rs.html#1-412">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>HTTP Authentication middleware.</p>
|
||||
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2>
|
||||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.HttpAuthentication.html" title="actix_web_httpauth::middleware::HttpAuthentication struct">HttpAuthentication</a></div><div class="item-right docblock-short"><p>Middleware for checking HTTP authentication.</p>
|
||||
</div></div></div></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="actix_web_httpauth" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.61.0-nightly (4ce374923 2022-02-28)" ></div>
|
||||
|
@ -360,6 +360,61 @@
|
||||
<span id="355">355</span>
|
||||
<span id="356">356</span>
|
||||
<span id="357">357</span>
|
||||
<span id="358">358</span>
|
||||
<span id="359">359</span>
|
||||
<span id="360">360</span>
|
||||
<span id="361">361</span>
|
||||
<span id="362">362</span>
|
||||
<span id="363">363</span>
|
||||
<span id="364">364</span>
|
||||
<span id="365">365</span>
|
||||
<span id="366">366</span>
|
||||
<span id="367">367</span>
|
||||
<span id="368">368</span>
|
||||
<span id="369">369</span>
|
||||
<span id="370">370</span>
|
||||
<span id="371">371</span>
|
||||
<span id="372">372</span>
|
||||
<span id="373">373</span>
|
||||
<span id="374">374</span>
|
||||
<span id="375">375</span>
|
||||
<span id="376">376</span>
|
||||
<span id="377">377</span>
|
||||
<span id="378">378</span>
|
||||
<span id="379">379</span>
|
||||
<span id="380">380</span>
|
||||
<span id="381">381</span>
|
||||
<span id="382">382</span>
|
||||
<span id="383">383</span>
|
||||
<span id="384">384</span>
|
||||
<span id="385">385</span>
|
||||
<span id="386">386</span>
|
||||
<span id="387">387</span>
|
||||
<span id="388">388</span>
|
||||
<span id="389">389</span>
|
||||
<span id="390">390</span>
|
||||
<span id="391">391</span>
|
||||
<span id="392">392</span>
|
||||
<span id="393">393</span>
|
||||
<span id="394">394</span>
|
||||
<span id="395">395</span>
|
||||
<span id="396">396</span>
|
||||
<span id="397">397</span>
|
||||
<span id="398">398</span>
|
||||
<span id="399">399</span>
|
||||
<span id="400">400</span>
|
||||
<span id="401">401</span>
|
||||
<span id="402">402</span>
|
||||
<span id="403">403</span>
|
||||
<span id="404">404</span>
|
||||
<span id="405">405</span>
|
||||
<span id="406">406</span>
|
||||
<span id="407">407</span>
|
||||
<span id="408">408</span>
|
||||
<span id="409">409</span>
|
||||
<span id="410">410</span>
|
||||
<span id="411">411</span>
|
||||
<span id="412">412</span>
|
||||
</pre><pre class="rust"><code><span class="doccomment">//! HTTP Authentication middleware.</span>
|
||||
|
||||
<span class="kw">use</span> <span class="ident">std</span>::{
|
||||
@ -602,10 +657,13 @@
|
||||
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">test</span>)]</span>
|
||||
<span class="kw">mod</span> <span class="ident">tests</span> {
|
||||
<span class="kw">use</span> <span class="kw">super</span>::<span class="kw-2">*</span>;
|
||||
<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::extractors::basic::BasicAuth</span>;
|
||||
<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::extractors::bearer::BearerAuth</span>;
|
||||
<span class="kw">use</span> <span class="ident">actix_service</span>::{<span class="ident">into_service</span>, <span class="ident">Service</span>};
|
||||
<span class="kw">use</span> <span class="ident">actix_web::error::ErrorForbidden</span>;
|
||||
<span class="kw">use</span> <span class="ident">actix_web::http::StatusCode</span>;
|
||||
<span class="kw">use</span> <span class="ident">actix_web::test::TestRequest</span>;
|
||||
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">error</span>, <span class="ident">HttpResponse</span>};
|
||||
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">error</span>, <span class="ident">web</span>, <span class="ident">App</span>, <span class="ident">HttpResponse</span>};
|
||||
|
||||
<span class="doccomment">/// This is a test for https://github.com/actix/actix-extras/issues/10</span>
|
||||
<span class="attribute">#[<span class="ident">actix_web::test</span>]</span>
|
||||
@ -716,6 +774,58 @@
|
||||
|
||||
<span class="macro">assert!</span>(<span class="ident">f</span>.<span class="ident">is_ok</span>());
|
||||
}
|
||||
|
||||
<span class="attribute">#[<span class="ident">actix_rt::test</span>]</span>
|
||||
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">test_middleware_works_with_app</span>() {
|
||||
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">validator</span>(
|
||||
<span class="ident">_req</span>: <span class="ident">ServiceRequest</span>,
|
||||
<span class="ident">_credentials</span>: <span class="ident">BasicAuth</span>,
|
||||
) -> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">ServiceRequest</span>, <span class="ident">actix_web::Error</span><span class="op">></span> {
|
||||
<span class="prelude-val">Err</span>(<span class="ident">ErrorForbidden</span>(<span class="string">"You are not welcome!"</span>))
|
||||
}
|
||||
<span class="kw">let</span> <span class="ident">middleware</span> <span class="op">=</span> <span class="ident">HttpAuthentication::basic</span>(<span class="ident">validator</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">srv</span> <span class="op">=</span> <span class="ident">actix_web::test::init_service</span>(
|
||||
<span class="ident">App::new</span>()
|
||||
.<span class="ident">wrap</span>(<span class="ident">middleware</span>)
|
||||
.<span class="ident">route</span>(<span class="string">"/"</span>, <span class="ident">web::get</span>().<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">web::HttpResponse::Ok</span>())),
|
||||
)
|
||||
.<span class="kw">await</span>;
|
||||
|
||||
<span class="kw">let</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">actix_web::test::TestRequest::with_uri</span>(<span class="string">"/"</span>)
|
||||
.<span class="ident">append_header</span>((<span class="string">"Authorization"</span>, <span class="string">"Basic DontCare"</span>))
|
||||
.<span class="ident">to_request</span>();
|
||||
|
||||
<span class="kw">let</span> <span class="ident">resp</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">call</span>(<span class="ident">req</span>).<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">resp</span>.<span class="ident">status</span>(), <span class="ident">StatusCode::UNAUTHORIZED</span>);
|
||||
}
|
||||
|
||||
<span class="attribute">#[<span class="ident">actix_rt::test</span>]</span>
|
||||
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">test_middleware_works_with_scope</span>() {
|
||||
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">validator</span>(
|
||||
<span class="ident">_req</span>: <span class="ident">ServiceRequest</span>,
|
||||
<span class="ident">_credentials</span>: <span class="ident">BasicAuth</span>,
|
||||
) -> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">ServiceRequest</span>, <span class="ident">actix_web::Error</span><span class="op">></span> {
|
||||
<span class="prelude-val">Err</span>(<span class="ident">ErrorForbidden</span>(<span class="string">"You are not welcome!"</span>))
|
||||
}
|
||||
<span class="kw">let</span> <span class="ident">middleware</span> <span class="op">=</span> <span class="ident">actix_web::middleware::Compat::new</span>(<span class="ident">HttpAuthentication::basic</span>(<span class="ident">validator</span>));
|
||||
|
||||
<span class="kw">let</span> <span class="ident">srv</span> <span class="op">=</span> <span class="ident">actix_web::test::init_service</span>(
|
||||
<span class="ident">App::new</span>().<span class="ident">service</span>(
|
||||
<span class="ident">web::scope</span>(<span class="string">"/"</span>)
|
||||
.<span class="ident">wrap</span>(<span class="ident">middleware</span>)
|
||||
.<span class="ident">route</span>(<span class="string">"/"</span>, <span class="ident">web::get</span>().<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">web::HttpResponse::Ok</span>())),
|
||||
),
|
||||
)
|
||||
.<span class="kw">await</span>;
|
||||
|
||||
<span class="kw">let</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">actix_web::test::TestRequest::with_uri</span>(<span class="string">"/"</span>)
|
||||
.<span class="ident">append_header</span>((<span class="string">"Authorization"</span>, <span class="string">"Basic DontCare"</span>))
|
||||
.<span class="ident">to_request</span>();
|
||||
|
||||
<span class="kw">let</span> <span class="ident">resp</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">call</span>(<span class="ident">req</span>).<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">resp</span>.<span class="ident">status</span>(), <span class="ident">StatusCode::UNAUTHORIZED</span>);
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
</section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="actix_web_httpauth" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.61.0-nightly (4ce374923 2022-02-28)" ></div>
|
||||
|
Loading…
Reference in New Issue
Block a user