2 * @brief self-test for liboauth.
4 * @author Robin Gareus <robin@gareus.org>
6 * This code contains examples provided by Eran Hammer-Lahav
7 * on the oauth.net mailing list.
9 * Copyright 2008, 2009 Robin Gareus <robin@gareus.org>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 #include "commontest.h"
41 int loglevel = 1; //< report each successful test
43 int main (int argc, char **argv) {
47 if (loglevel) printf("\n *** testing liboauth against Eran's Test cases ***\n http://groups.google.com/group/oauth/browse_frm/thread/243f4da439fd1f51?hl=en\n");
49 // Eran's test-cases - http://groups.google.com/group/oauth/browse_frm/thread/243f4da439fd1f51?hl=en
50 fail|=test_encoding("1234=asdf=4567","1234%3Dasdf%3D4567");
51 fail|=test_encoding("asdf-4354=asew-5698","asdf-4354%3Dasew-5698");
52 fail|=test_encoding("erks823*43=asd&123ls%23","erks823%2A43%3Dasd%26123ls%2523");
53 fail|=test_encoding("dis9$#$Js009%==","dis9%24%23%24Js009%25%3D%3D");
54 fail|=test_encoding("3jd834jd9","3jd834jd9");
55 fail|=test_encoding("12303202302","12303202302");
56 fail|=test_encoding("taken with a 30% orange filter","taken%20with%20a%2030%25%20orange%20filter");
57 fail|=test_encoding("mountain & water view","mountain%20%26%20water%20view");
59 fail|=test_request("GET", "http://example.com:80/photo" "?"
61 "&oauth_consumer_key=1234=asdf=4567"
62 "&oauth_timestamp=12303202302"
63 "&oauth_nonce=3jd834jd9"
64 "&oauth_token=asdf-4354=asew-5698"
65 "&oauth_signature_method=HMAC-SHA1"
66 "&title=taken with a 30% orange filter"
67 "&file=mountain \001 water view"
71 "GET&http%3A%2F%2Fexample.com%2Fphoto&file%3Dmountain%2520%2526%2520water%2520view%26format%3Djpeg%26include%3Daperture%26include%3Ddate%26oauth_consumer_key%3D1234%253Dasdf%253D4567%26oauth_nonce%3D3jd834jd9%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D12303202302%26oauth_token%3Dasdf-4354%253Dasew-5698%26oauth_version%3D1.0%26title%3Dtaken%2520with%2520a%252030%2525%2520orange%2520filter" );
73 tmptst = oauth_sign_url2(
74 "http://example.com:80/photo" "?"
76 "&oauth_timestamp=12303202302"
77 "&oauth_nonce=3jd834jd9"
78 "&title=taken with a 30% orange filter"
79 "&file=mountain \001 water view"
83 NULL, OA_HMAC, NULL, "1234=asdf=4567", "erks823*43=asd&123ls%23", "asdf-4354=asew-5698", "dis9$#$Js009%==");
84 if (strcmp(tmptst,"http://example.com/photo?file=mountain%20%26%20water%20view&format=jpeg&include=aperture&include=date&oauth_consumer_key=1234%3Dasdf%3D4567&oauth_nonce=3jd834jd9&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12303202302&oauth_token=asdf-4354%3Dasew-5698&oauth_version=1.0&title=taken%20with%20a%2030%25%20orange%20filter&oauth_signature=jMdUSR1vOr3SzNv3gZ5DDDuGirA%3D")) {
85 printf(" got '%s'\n expected: '%s'\n",tmptst, "http://example.com/photo?file=mountain%20%26%20water%20view&format=jpeg&include=aperture&include=date&oauth_consumer_key=1234%3Dasdf%3D4567&oauth_nonce=3jd834jd9&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12303202302&oauth_token=asdf-4354%3Dasew-5698&oauth_version=1.0&title=taken%20with%20a%2030%25%20orange%20filter&oauth_signature=jMdUSR1vOr3SzNv3gZ5DDDuGirA%3D");
87 } else if (loglevel) printf("request signature ok.\n");
88 if(tmptst) free(tmptst);
92 printf("\n !!! One or more of Eran's Test Cases failed.\n\n");
94 printf(" *** Eran's Test-Cases verified sucessfully.\n");