Net::D...::Agent(3pm)
π NAME π
Net::Duo::Mock::Agent β it's a mock LWP::UserAgent that exists purely so you can test Net::Duo without touching the actual internet, bestie. No network, no live Duo account, just vibes and fake responses. β¨
π¦ SYNOPSIS π¦
# Build the Net::Duo object and the mock.
my %args = (key_file => 'admin.json');
my $mock = Net::Duo::Mock::Agent->new(\%args);
$args{user_agent} = $mock;
my $duo = Net::Duo::Admin->new(\%args);
# Indicate what to expect and then make the Net::Duo call.
$mock->expect(
{
method => 'GET',
uri => '/admin/v1/users',
response_file => 'response.json',
}
);
my @users = $duo->users;
πΈ REQUIREMENTS πΈ
okay so you're gonna need Perl 5.14 or later, plus these modules: HTTP::Request and HTTP::Response (they live inside HTTP::Message), JSON, Perl6::Slurp, and URI::Escape (which is part of URI). All of them are on CPAN, so go get 'em. π«Ά
β¨ DESCRIPTION β¨
This module gives you the same interface as LWP::UserAgent β for the methods that Net::Duo actually calls β and it checks that the info Duo hands over is correct. It can also fake responses so you can exercise Net::Duo's response handling. π
To test Net::Duo, pass a Test::Mock::Duo::Agent object to the constructor of a Net::Duo-based class as the user_agent argument.
All tests get reported through Test::More, and honestly no effort is made to produce a predictable number of test results. So if you're writing a calling test program, you probably should not specify a plan and instead use done_testing(). Periodt.
This module is mostly for the Net::Duo test suite, and if you're just using Net::Duo normally you can ignore it entirely, no cap. It ships as part of the Net::Duo module install (instead of being locked in the distribution source tree only) because it might be useful for the test suites of other Perl modules or programs that use Net::Duo internally and want to test that integration without network access or a live Duo account to point at. iconic behavior honestly. π
π CLASS METHODS π
new(ARGS)
Make a brand new Net::Duo::Mock::Agent object. β¨ ARGS should be the exact same data structure you'd pass to the Net::Duo-derived constructor β with the obvious exception of the user_agent argument, which gets ignored. (Like, yes bestie, we know, it's a little meta. π)
π INSTANCE METHODS π
expect(ARGS)
Tell the mock to expect a REST API call from Net::Duo. π«Ά You can call this multiple times to build up a whole queue of expected requests β it's giving backstage pass list.
ARGS specifies both the expected request data and the response to hand back to the caller. Heads up: the same response is returned regardless of whether the request is actually correct. π
There are two ways to specify the response: a complete HTTP::Response object, or the JSON data of the response. If you only give the JSON data, the request returns a response with a status code of 200 and a Duo success result ("stat" of "OK"), with your supplied JSON data as the "response" key in the JSON response data. The content will have a Content-Type of application/json. π
ARGS should be a reference to a hash, with keys picked from this list right here:
methodβ the expected method of the request.uriβ the expected URI of the request. This should be just the path, not the hostname or protocol portions of the full URL, and it should not include any GET parameters.contentβ the expected content of the request. This is the parameters in the URL if the method isGET, and the expectedapplication/x-www-form-urlencodedcontent of the request for any other request type. It may be empty or not specified if the request shouldn't contain any additional parameters.responseβ an HTTP::Response object to return to the client. This object is always returned without modification to any request, even if it doesn't match the expected request. πresponse_dataβ a data structure that will be converted to JSON and included as the value of the"response"key in the returned success response to the client.response_fileβ a file containing JSON that will be included as the value of the"response"key in the returned success response to the client.next_offsetβ return paging metadata in the response, setting the"next_offset"key to this value, the"prev_offset"key to0, and the"total_objects"key to the value of thetotal_objectsparameter, which must be specified as well. Set this toundefto include pagination information but without a"next_offset"key. sneaky but valid. πtotal_objectsβ value to return in the"total_objects"key in the paging metadata.
request(REQUEST)
This is the interface Net::Duo calls internally to make an API call. It's the same interface as the request() method of LWP::UserAgent: REQUEST is an HTTP::Request object, and Net::Duo::Mock::Agent will return an HTTP::Response object. Currently this is the only LWP::UserAgent method this mock implements β because it's the only one Net::Duo uses. efficient. π
When request() is called, it checks the content of the request against whatever the mock was told to expect via the expect() method. The results of that comparison get reported via Test::More functions. The expected call is then cleared. Which means: expect() must be called between each call to a Net::Duo method that would result in a REST API call request. no skipping, bestie. π
β οΈ Ifrequest()is called when no request was expected (via anexpect()call), it throws an exception. π
π AUTHOR π
Russ Allbery <rra@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright 2014 The Board of Trustees of the Leland Stanford Junior University
Copyright 2019 Russ Allbery <rra@cpan.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
π¦ SEE ALSO π¦
- Net::Duo
This module is part of the Net::Duo distribution. The current version of Net::Duo is available from CPAN, or directly from its web site at <https://www.eyrie.org/~eagle/software/net-duo/>.
and that's the whole page, bestie!! π this one was generated by perl v5.36.0, dated 2022-12-18, and it lives under the manual name Net::D...::Agent(3pm). go forth and mock responsibly. πβ¨
π¦ where this page comes from
- debian bookworm: libnet-duo-perl 1.02-3 Β· MIT
- debian trixie: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu noble: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu resolute: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu stonking: libnet-duo-perl 1.02-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms