2 * @brief self-test for liboauth.
4 * @author Robin Gareus <robin@gareus.org>
6 * Copyright 2009, 2010, 2012 Robin Gareus <robin@gareus.org>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 #include "commontest.h"
34 int loglevel = 1; //< report each successful test
36 int main (int argc, char **argv) {
39 if (loglevel) printf("\n *** Testing query parameter array encoding.\n");
41 fail|=test_request("GET", "http://example.com"
48 "GET&http%3A%2F%2Fexample.com%2F&a1%255Baa1%255D%255Baak1%255D%3Daav1%26a1%255Baa1%255D%255Baak2%255D%3Daav2%26a1%255Bak1%255D%3Dav1%26a1%255Bak2%255D%3Dav2%26k1%3Dv1%26k2%3Dv2");
50 if (loglevel) printf("\n *** Testing http://tools.ietf.org/html/rfc5849 example.\n");
52 fail|=test_request("GET", "http://example.com"
53 "/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b"
55 "&oauth_consumer_key=9djdj82h48djs9d2"
56 "&oauth_token=kkk9d7dh3k39sjv7"
57 "&oauth_signature_method=HMAC-SHA1"
58 "&oauth_timestamp=137131201"
59 "&oauth_nonce=7d8f3e4a"
60 "&oauth_signature=djosJKDKJSD8743243%2Fjdk33klY%3D",
61 "GET&http%3A%2F%2Fexample.com%2Frequest&a2%3Dr%2520b%26a3%3D2%2520q%26a3%3Da%26b5%3D%253D%25253D%26c%2540%3D%26c2%3D%26oauth_consumer_key%3D9djdj82h48djs9d2%26oauth_nonce%3D7d8f3e4a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D137131201%26oauth_token%3Dkkk9d7dh3k39sjv7");
63 if (loglevel) printf("\n *** Testing body hash calculation.\n");
66 const char *teststring="Hello World!";
67 bh=oauth_body_hash_data(strlen(teststring), teststring);
69 if (strcmp(bh,"oauth_body_hash=Lve95gjOVATpfV8EL5X4nxwjKHE=")) fail|=1;
75 if (loglevel) printf("\n *** Testing PLAINTEXT signature.\n");
76 fail |= test_sign_get(
77 "http://host.net/resource" "?" "name=value&name=value"
78 "&oauth_nonce=fake&&oauth_timestamp=1",
82 "http://host.net/resource?name=value&name=value&oauth_consumer_key=abcd&oauth_nonce=fake&oauth_signature_method=PLAINTEXT&oauth_timestamp=1&oauth_token=1234&oauth_version=1.0&oauth_signature=%2526%26%2526"
88 printf("\n !!! One or more test cases failed.\n\n");
90 printf(" *** Test cases verified sucessfully.\n");