File: testcert.cpp

package info (click to toggle)
davix 0.8.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,184 kB
  • sloc: ansic: 164,612; cpp: 38,741; python: 17,726; perl: 14,124; sh: 13,458; xml: 3,567; makefile: 1,959; javascript: 885; pascal: 570; lisp: 7
file content (66 lines) | stat: -rw-r--r-- 2,016 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <davix.hpp>
#include <davixcontext.hpp>
#include <params/davixrequestparams.hpp>
#include <auth/davixauth.hpp>
#include <gtest/gtest.h>

using namespace std;
using namespace Davix;

// instanciate and play with gates
// TEST(CredTest, basicLoad){
//     DavixError* tmp_err=NULL;
//     davix_set_log_level(DAVIX_LOG_DEBUG | DAVIX_LOG_WARNING | DAVIX_LOG_TRACE);

//     Context c;
//     X509Credential cred;

//     ASSERT_FALSE(cred.hasCert());

//     string cert_path(TEST_VALID_CERT);
//     string cert_pass(TEST_VALID_CERT_PASS);

//     cout << " cred: " << cert_path << "pass " << cert_pass << endl;

//     int ret = cred.loadFromFileP12(cert_path.c_str(), cert_pass.c_str(), &tmp_err);
//     if(tmp_err){
//         cout << "err :" << tmp_err->getErrMsg() << endl;
//     }
//     ASSERT_EQ(0, ret);
//     ASSERT_EQ(NULL, tmp_err);
//     ASSERT_TRUE(cred.hasCert());

//     X509Credential cred2(cred);
//     ASSERT_TRUE(cred2.hasCert());

//     ret = cred.loadFromFileP12("/random/stupid/path", "", &tmp_err);
//     ASSERT_EQ(-1, ret);
//     ASSERT_EQ(StatusCode::CredentialNotFound, tmp_err->getStatus());
//     DavixError::clearError(&tmp_err);
//     ASSERT_FALSE(cred.hasCert());
//     ASSERT_TRUE(cred2.hasCert());

//     ret = cred.loadFromFileP12(cert_path.c_str(), "", &tmp_err);
//     ASSERT_EQ(-1, ret);
//     ASSERT_EQ(StatusCode::LoginPasswordError, tmp_err->getStatus());
//     DavixError::clearError(&tmp_err);

// }


TEST(testAWS, awsToken){
    std::string p_key("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
    std::string a_key("AKIAIOSFODNN7EXAMPLE");
    std::string req("GET\n"
                    "\n"
                    "\n"
                    "Tue, 27 Mar 2007 19:36:42 +0000\n"
                    "/johnsmith/photos/puppy.jpg");
    std::string token("AWS AKIAIOSFODNN7EXAMPLE:"
                      "bWq2s1WEIj+Ydj0vQ697zp+IXMU=");


    std::string res = getAwsAuthorizationField(req, p_key, a_key);
    ASSERT_STREQ(res.c_str(), token.c_str());

}