// // Created by xajhu on 2019/12/2 0002. // #include using namespace std; #include "gtest/gtest.h" extern "C" { #include "err_code.h" #include "json_interface.h" #include "restful.h" } TEST(ztp_auth, authorized_success) { #define JSON_REQ ("{\"ESN\": \"tt21\"}") #define REQ_URL ("http://172.28.73.43:8088/device/esn") int ret; unsigned int size = 4096; char buf[4096]; PAUTH_ZTH_RSP pZTPRsp; memset(buf, 0, 4096); ret = http_post_request(REQ_URL, JSON_REQ, (unsigned char *)buf, &size); ASSERT_EQ(ERR_OK, ret); ret = Json2Struct(buf, &pZTPRsp, JE_AUTH_ZTP, false); ASSERT_EQ(ERR_OK, ret); ASSERT_STRCASEEQ(pZTPRsp->status, "SUCCESS") << "\nValue-->[" << "status: " << pZTPRsp->status << ", code: " << pZTPRsp->code << ", ip: " << pZTPRsp->ip << ", iptype: " << pZTPRsp->iptype << "]" <status) { free(pZTPRsp->status); } if(pZTPRsp->code) { free(pZTPRsp->code); } if(pZTPRsp->ip) { free(pZTPRsp->ip); } free(pZTPRsp); } } TEST(ztp_auth, unauthorized_failed) { #define JSON_REQ_FAIL ("{\"ESN\": \"ace08484843\"}") int ret; unsigned int size = 4096; char buf[4096]; PAUTH_ZTH_RSP pZTPRsp; memset(buf, 0, 4096); ret = http_post_request(REQ_URL, JSON_REQ_FAIL, (unsigned char *)buf, &size); EXPECT_EQ(ERR_OK, ret); ret = Json2Struct(buf, &pZTPRsp, JE_AUTH_ZTP, false); ASSERT_EQ(ERR_OK, ret); ASSERT_STRCASEEQ(pZTPRsp->status, "FAILED"); if(pZTPRsp) { if(pZTPRsp->status) { free(pZTPRsp->status); } if(pZTPRsp->code) { free(pZTPRsp->code); } if(pZTPRsp->ip) { free(pZTPRsp->ip); } free(pZTPRsp); } }