Ram Gandikota
/
metronome
FRDM K64F Metronome
mbed-client/test/mbedclient/utest/m2msecurity/test_m2msecurity.cpp@0:a2cb7295a1f7, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:35:07 2017 +0000
- Revision:
- 0:a2cb7295a1f7
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a2cb7295a1f7 | 1 | /* |
ram54288 | 0:a2cb7295a1f7 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a2cb7295a1f7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a2cb7295a1f7 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a2cb7295a1f7 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a2cb7295a1f7 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a2cb7295a1f7 | 7 | * |
ram54288 | 0:a2cb7295a1f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a2cb7295a1f7 | 9 | * |
ram54288 | 0:a2cb7295a1f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a2cb7295a1f7 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a2cb7295a1f7 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a2cb7295a1f7 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a2cb7295a1f7 | 14 | * limitations under the License. |
ram54288 | 0:a2cb7295a1f7 | 15 | */ |
ram54288 | 0:a2cb7295a1f7 | 16 | #include "CppUTest/TestHarness.h" |
ram54288 | 0:a2cb7295a1f7 | 17 | #include "test_m2msecurity.h" |
ram54288 | 0:a2cb7295a1f7 | 18 | #include "m2mobject_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 19 | #include "m2mobjectinstance_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 20 | #include "m2mresource_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 21 | #include "m2mresourceinstance_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 22 | #include "m2mbase_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 23 | #include "nsdlaccesshelper_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 24 | |
ram54288 | 0:a2cb7295a1f7 | 25 | Test_M2MSecurity::Test_M2MSecurity() |
ram54288 | 0:a2cb7295a1f7 | 26 | { |
ram54288 | 0:a2cb7295a1f7 | 27 | M2MObject* obj = new M2MObject("name", "name"); |
ram54288 | 0:a2cb7295a1f7 | 28 | m2mobject_stub::inst = new M2MObjectInstance(*obj,"name","type", "name"); |
ram54288 | 0:a2cb7295a1f7 | 29 | m2mresource_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 30 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 31 | "name", |
ram54288 | 0:a2cb7295a1f7 | 32 | "type", |
ram54288 | 0:a2cb7295a1f7 | 33 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 34 | false, |
ram54288 | 0:a2cb7295a1f7 | 35 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 36 | security = new M2MSecurity(M2MSecurity::Bootstrap); |
ram54288 | 0:a2cb7295a1f7 | 37 | |
ram54288 | 0:a2cb7295a1f7 | 38 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a2cb7295a1f7 | 39 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 40 | |
ram54288 | 0:a2cb7295a1f7 | 41 | delete obj; |
ram54288 | 0:a2cb7295a1f7 | 42 | } |
ram54288 | 0:a2cb7295a1f7 | 43 | |
ram54288 | 0:a2cb7295a1f7 | 44 | Test_M2MSecurity::~Test_M2MSecurity() |
ram54288 | 0:a2cb7295a1f7 | 45 | { |
ram54288 | 0:a2cb7295a1f7 | 46 | delete m2mobject_stub::inst; |
ram54288 | 0:a2cb7295a1f7 | 47 | m2mobject_stub::inst = NULL; |
ram54288 | 0:a2cb7295a1f7 | 48 | m2mobject_stub::clear(); |
ram54288 | 0:a2cb7295a1f7 | 49 | m2mobjectinstance_stub::clear(); |
ram54288 | 0:a2cb7295a1f7 | 50 | m2mresource_stub::clear(); |
ram54288 | 0:a2cb7295a1f7 | 51 | m2mbase_stub::clear(); |
ram54288 | 0:a2cb7295a1f7 | 52 | delete security; |
ram54288 | 0:a2cb7295a1f7 | 53 | } |
ram54288 | 0:a2cb7295a1f7 | 54 | |
ram54288 | 0:a2cb7295a1f7 | 55 | void Test_M2MSecurity::test_create_resource_int() |
ram54288 | 0:a2cb7295a1f7 | 56 | { |
ram54288 | 0:a2cb7295a1f7 | 57 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 58 | "name", |
ram54288 | 0:a2cb7295a1f7 | 59 | "type", |
ram54288 | 0:a2cb7295a1f7 | 60 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 61 | false, |
ram54288 | 0:a2cb7295a1f7 | 62 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 63 | |
ram54288 | 0:a2cb7295a1f7 | 64 | CHECK(security->create_resource(M2MSecurity::M2MServerUri,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 65 | CHECK(security->create_resource(M2MSecurity::BootstrapServer,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 66 | CHECK(security->create_resource(M2MSecurity::SecurityMode,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 67 | CHECK(security->create_resource(M2MSecurity::PublicKey,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 68 | CHECK(security->create_resource(M2MSecurity::ServerPublicKey,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 69 | CHECK(security->create_resource(M2MSecurity::Secretkey,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 70 | CHECK(security->create_resource(M2MSecurity::SMSBindingKey,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 71 | CHECK(security->create_resource(M2MSecurity::SMSBindingSecretKey,10) == NULL); |
ram54288 | 0:a2cb7295a1f7 | 72 | |
ram54288 | 0:a2cb7295a1f7 | 73 | CHECK(security->create_resource(M2MSecurity::M2MServerSMSNumber,10) != NULL); |
ram54288 | 0:a2cb7295a1f7 | 74 | CHECK(security->create_resource(M2MSecurity::ShortServerID,10) != NULL); |
ram54288 | 0:a2cb7295a1f7 | 75 | CHECK(security->create_resource(M2MSecurity::ClientHoldOffTime,10) != NULL); |
ram54288 | 0:a2cb7295a1f7 | 76 | CHECK(security->create_resource(M2MSecurity::SMSSecurityMode,10) != NULL); |
ram54288 | 0:a2cb7295a1f7 | 77 | |
ram54288 | 0:a2cb7295a1f7 | 78 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a2cb7295a1f7 | 79 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 80 | } |
ram54288 | 0:a2cb7295a1f7 | 81 | |
ram54288 | 0:a2cb7295a1f7 | 82 | void Test_M2MSecurity::test_delete_resource() |
ram54288 | 0:a2cb7295a1f7 | 83 | { |
ram54288 | 0:a2cb7295a1f7 | 84 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 85 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 86 | "name", |
ram54288 | 0:a2cb7295a1f7 | 87 | "type", |
ram54288 | 0:a2cb7295a1f7 | 88 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 89 | false, |
ram54288 | 0:a2cb7295a1f7 | 90 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 91 | |
ram54288 | 0:a2cb7295a1f7 | 92 | CHECK(security->delete_resource(M2MSecurity::SMSBindingSecretKey) == false); |
ram54288 | 0:a2cb7295a1f7 | 93 | CHECK(security->delete_resource(M2MSecurity::SMSBindingKey) == false); |
ram54288 | 0:a2cb7295a1f7 | 94 | CHECK(security->delete_resource(M2MSecurity::M2MServerUri) == false); |
ram54288 | 0:a2cb7295a1f7 | 95 | CHECK(security->delete_resource(M2MSecurity::Secretkey) == false); |
ram54288 | 0:a2cb7295a1f7 | 96 | CHECK(security->delete_resource(M2MSecurity::ServerPublicKey) == false); |
ram54288 | 0:a2cb7295a1f7 | 97 | CHECK(security->delete_resource(M2MSecurity::BootstrapServer) == false); |
ram54288 | 0:a2cb7295a1f7 | 98 | CHECK(security->delete_resource(M2MSecurity::PublicKey) == false); |
ram54288 | 0:a2cb7295a1f7 | 99 | CHECK(security->delete_resource(M2MSecurity::SecurityMode) == false); |
ram54288 | 0:a2cb7295a1f7 | 100 | |
ram54288 | 0:a2cb7295a1f7 | 101 | m2mobjectinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 102 | |
ram54288 | 0:a2cb7295a1f7 | 103 | CHECK(security->delete_resource(M2MSecurity::M2MServerSMSNumber) == true); |
ram54288 | 0:a2cb7295a1f7 | 104 | CHECK(security->delete_resource(M2MSecurity::ShortServerID) == true); |
ram54288 | 0:a2cb7295a1f7 | 105 | CHECK(security->delete_resource(M2MSecurity::ClientHoldOffTime) == true); |
ram54288 | 0:a2cb7295a1f7 | 106 | CHECK(security->delete_resource(M2MSecurity::SMSSecurityMode) == true); |
ram54288 | 0:a2cb7295a1f7 | 107 | |
ram54288 | 0:a2cb7295a1f7 | 108 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 109 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 110 | } |
ram54288 | 0:a2cb7295a1f7 | 111 | |
ram54288 | 0:a2cb7295a1f7 | 112 | void Test_M2MSecurity::test_set_resource_value_string() |
ram54288 | 0:a2cb7295a1f7 | 113 | { |
ram54288 | 0:a2cb7295a1f7 | 114 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 115 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 116 | "name", |
ram54288 | 0:a2cb7295a1f7 | 117 | "type", |
ram54288 | 0:a2cb7295a1f7 | 118 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 119 | false, |
ram54288 | 0:a2cb7295a1f7 | 120 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 121 | |
ram54288 | 0:a2cb7295a1f7 | 122 | CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,"test") == true); |
ram54288 | 0:a2cb7295a1f7 | 123 | |
ram54288 | 0:a2cb7295a1f7 | 124 | CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 125 | CHECK(security->set_resource_value(M2MSecurity::ShortServerID,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 126 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 127 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 128 | CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 129 | CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 130 | CHECK(security->set_resource_value(M2MSecurity::Secretkey,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 131 | CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 132 | CHECK(security->set_resource_value(M2MSecurity::PublicKey,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 133 | CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 134 | CHECK(security->set_resource_value(M2MSecurity::SecurityMode,"test") == false); |
ram54288 | 0:a2cb7295a1f7 | 135 | |
ram54288 | 0:a2cb7295a1f7 | 136 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 137 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 138 | } |
ram54288 | 0:a2cb7295a1f7 | 139 | |
ram54288 | 0:a2cb7295a1f7 | 140 | void Test_M2MSecurity::test_set_resource_value_int() |
ram54288 | 0:a2cb7295a1f7 | 141 | { |
ram54288 | 0:a2cb7295a1f7 | 142 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 143 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 144 | "name", |
ram54288 | 0:a2cb7295a1f7 | 145 | "type", |
ram54288 | 0:a2cb7295a1f7 | 146 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 147 | false, |
ram54288 | 0:a2cb7295a1f7 | 148 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 149 | |
ram54288 | 0:a2cb7295a1f7 | 150 | CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 151 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 152 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 153 | CHECK(security->set_resource_value(M2MSecurity::Secretkey,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 154 | CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 155 | CHECK(security->set_resource_value(M2MSecurity::PublicKey,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 156 | CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,10) == false); |
ram54288 | 0:a2cb7295a1f7 | 157 | |
ram54288 | 0:a2cb7295a1f7 | 158 | CHECK(security->set_resource_value(M2MSecurity::SecurityMode,10) == true); |
ram54288 | 0:a2cb7295a1f7 | 159 | CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,10) == true); |
ram54288 | 0:a2cb7295a1f7 | 160 | CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,10) == true); |
ram54288 | 0:a2cb7295a1f7 | 161 | CHECK(security->set_resource_value(M2MSecurity::ShortServerID,10) == true); |
ram54288 | 0:a2cb7295a1f7 | 162 | CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,10) == true); |
ram54288 | 0:a2cb7295a1f7 | 163 | |
ram54288 | 0:a2cb7295a1f7 | 164 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 165 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 166 | } |
ram54288 | 0:a2cb7295a1f7 | 167 | |
ram54288 | 0:a2cb7295a1f7 | 168 | void Test_M2MSecurity::test_set_resource_value_buffer() |
ram54288 | 0:a2cb7295a1f7 | 169 | { |
ram54288 | 0:a2cb7295a1f7 | 170 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 171 | |
ram54288 | 0:a2cb7295a1f7 | 172 | uint8_t value[] = {"value"}; |
ram54288 | 0:a2cb7295a1f7 | 173 | uint16_t length = (uint16_t)sizeof(value); |
ram54288 | 0:a2cb7295a1f7 | 174 | |
ram54288 | 0:a2cb7295a1f7 | 175 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 176 | "name", |
ram54288 | 0:a2cb7295a1f7 | 177 | "type", |
ram54288 | 0:a2cb7295a1f7 | 178 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 179 | false, |
ram54288 | 0:a2cb7295a1f7 | 180 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 181 | |
ram54288 | 0:a2cb7295a1f7 | 182 | CHECK(security->set_resource_value(M2MSecurity::Secretkey,value,length) == true); |
ram54288 | 0:a2cb7295a1f7 | 183 | CHECK(security->set_resource_value(M2MSecurity::ServerPublicKey,value,length) == true); |
ram54288 | 0:a2cb7295a1f7 | 184 | CHECK(security->set_resource_value(M2MSecurity::PublicKey,value,length) == true); |
ram54288 | 0:a2cb7295a1f7 | 185 | |
ram54288 | 0:a2cb7295a1f7 | 186 | CHECK(security->set_resource_value(M2MSecurity::M2MServerUri,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 187 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingKey,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 188 | CHECK(security->set_resource_value(M2MSecurity::SMSBindingSecretKey,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 189 | CHECK(security->set_resource_value(M2MSecurity::BootstrapServer,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 190 | |
ram54288 | 0:a2cb7295a1f7 | 191 | CHECK(security->set_resource_value(M2MSecurity::SecurityMode,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 192 | CHECK(security->set_resource_value(M2MSecurity::SMSSecurityMode,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 193 | CHECK(security->set_resource_value(M2MSecurity::M2MServerSMSNumber,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 194 | CHECK(security->set_resource_value(M2MSecurity::ShortServerID,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 195 | CHECK(security->set_resource_value(M2MSecurity::ClientHoldOffTime,value,length) == false); |
ram54288 | 0:a2cb7295a1f7 | 196 | |
ram54288 | 0:a2cb7295a1f7 | 197 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 198 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 199 | } |
ram54288 | 0:a2cb7295a1f7 | 200 | |
ram54288 | 0:a2cb7295a1f7 | 201 | void Test_M2MSecurity::test_resource_value_int() |
ram54288 | 0:a2cb7295a1f7 | 202 | { |
ram54288 | 0:a2cb7295a1f7 | 203 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 204 | |
ram54288 | 0:a2cb7295a1f7 | 205 | uint8_t value[] = {"10"}; |
ram54288 | 0:a2cb7295a1f7 | 206 | //m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 207 | uint8_t size = 0; |
ram54288 | 0:a2cb7295a1f7 | 208 | m2mresourceinstance_stub::value = String::convert_integer_to_array(10,size); |
ram54288 | 0:a2cb7295a1f7 | 209 | /*memset(m2mresourceinstance_stub::value,0,(uint32_t)size); |
ram54288 | 0:a2cb7295a1f7 | 210 | memcpy(m2mresourceinstance_stub::value, 10, size);*/ |
ram54288 | 0:a2cb7295a1f7 | 211 | m2mresourceinstance_stub::int_value = (uint16_t)size; |
ram54288 | 0:a2cb7295a1f7 | 212 | |
ram54288 | 0:a2cb7295a1f7 | 213 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 214 | "name", |
ram54288 | 0:a2cb7295a1f7 | 215 | "type", |
ram54288 | 0:a2cb7295a1f7 | 216 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 217 | false, |
ram54288 | 0:a2cb7295a1f7 | 218 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 219 | |
ram54288 | 0:a2cb7295a1f7 | 220 | CHECK(security->resource_value_int(M2MSecurity::SecurityMode) == 10); |
ram54288 | 0:a2cb7295a1f7 | 221 | CHECK(security->resource_value_int(M2MSecurity::SMSSecurityMode) == 10); |
ram54288 | 0:a2cb7295a1f7 | 222 | CHECK(security->resource_value_int(M2MSecurity::M2MServerSMSNumber) == 10); |
ram54288 | 0:a2cb7295a1f7 | 223 | CHECK(security->resource_value_int(M2MSecurity::ShortServerID) == 10); |
ram54288 | 0:a2cb7295a1f7 | 224 | CHECK(security->resource_value_int(M2MSecurity::ClientHoldOffTime) == 10); |
ram54288 | 0:a2cb7295a1f7 | 225 | CHECK(security->resource_value_int(M2MSecurity::BootstrapServer) == 0); |
ram54288 | 0:a2cb7295a1f7 | 226 | CHECK(security->resource_value_int(M2MSecurity::PublicKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 227 | CHECK(security->resource_value_int(M2MSecurity::ServerPublicKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 228 | CHECK(security->resource_value_int(M2MSecurity::Secretkey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 229 | CHECK(security->resource_value_int(M2MSecurity::SMSBindingSecretKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 230 | CHECK(security->resource_value_int(M2MSecurity::SMSBindingKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 231 | CHECK(security->resource_value_int(M2MSecurity::M2MServerUri) == 0); |
ram54288 | 0:a2cb7295a1f7 | 232 | |
ram54288 | 0:a2cb7295a1f7 | 233 | security->clear_resources(); |
ram54288 | 0:a2cb7295a1f7 | 234 | CHECK(security->resource_value_int(M2MSecurity::SecurityMode) == 0); |
ram54288 | 0:a2cb7295a1f7 | 235 | CHECK(security->resource_value_int(M2MSecurity::SMSSecurityMode) == 0); |
ram54288 | 0:a2cb7295a1f7 | 236 | CHECK(security->resource_value_int(M2MSecurity::M2MServerSMSNumber) == 0); |
ram54288 | 0:a2cb7295a1f7 | 237 | CHECK(security->resource_value_int(M2MSecurity::ShortServerID) == 0); |
ram54288 | 0:a2cb7295a1f7 | 238 | CHECK(security->resource_value_int(M2MSecurity::ClientHoldOffTime) == 0); |
ram54288 | 0:a2cb7295a1f7 | 239 | CHECK(security->resource_value_int(M2MSecurity::BootstrapServer) == 0); |
ram54288 | 0:a2cb7295a1f7 | 240 | CHECK(security->resource_value_int(M2MSecurity::PublicKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 241 | CHECK(security->resource_value_int(M2MSecurity::ServerPublicKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 242 | CHECK(security->resource_value_int(M2MSecurity::Secretkey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 243 | CHECK(security->resource_value_int(M2MSecurity::SMSBindingSecretKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 244 | CHECK(security->resource_value_int(M2MSecurity::SMSBindingKey) == 0); |
ram54288 | 0:a2cb7295a1f7 | 245 | CHECK(security->resource_value_int(M2MSecurity::M2MServerUri) == 0); |
ram54288 | 0:a2cb7295a1f7 | 246 | |
ram54288 | 0:a2cb7295a1f7 | 247 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 248 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 249 | |
ram54288 | 0:a2cb7295a1f7 | 250 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a2cb7295a1f7 | 251 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a2cb7295a1f7 | 252 | } |
ram54288 | 0:a2cb7295a1f7 | 253 | |
ram54288 | 0:a2cb7295a1f7 | 254 | void Test_M2MSecurity::test_resource_value_string() |
ram54288 | 0:a2cb7295a1f7 | 255 | { |
ram54288 | 0:a2cb7295a1f7 | 256 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 257 | String test = "string"; |
ram54288 | 0:a2cb7295a1f7 | 258 | uint8_t value[] = {"string"}; |
ram54288 | 0:a2cb7295a1f7 | 259 | m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 260 | memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 261 | memcpy(m2mresourceinstance_stub::value,value,sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 262 | m2mresourceinstance_stub::int_value = (uint16_t)sizeof(value); |
ram54288 | 0:a2cb7295a1f7 | 263 | |
ram54288 | 0:a2cb7295a1f7 | 264 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 265 | "name", |
ram54288 | 0:a2cb7295a1f7 | 266 | "type", |
ram54288 | 0:a2cb7295a1f7 | 267 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 268 | false, |
ram54288 | 0:a2cb7295a1f7 | 269 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 270 | |
ram54288 | 0:a2cb7295a1f7 | 271 | CHECK(security->resource_value_string(M2MSecurity::M2MServerUri) == test); |
ram54288 | 0:a2cb7295a1f7 | 272 | |
ram54288 | 0:a2cb7295a1f7 | 273 | CHECK(security->resource_value_string(M2MSecurity::SMSBindingKey) == ""); |
ram54288 | 0:a2cb7295a1f7 | 274 | CHECK(security->resource_value_string(M2MSecurity::SMSBindingSecretKey) == ""); |
ram54288 | 0:a2cb7295a1f7 | 275 | CHECK(security->resource_value_string(M2MSecurity::Secretkey) == ""); |
ram54288 | 0:a2cb7295a1f7 | 276 | CHECK(security->resource_value_string(M2MSecurity::ServerPublicKey) == ""); |
ram54288 | 0:a2cb7295a1f7 | 277 | CHECK(security->resource_value_string(M2MSecurity::PublicKey) == ""); |
ram54288 | 0:a2cb7295a1f7 | 278 | CHECK(security->resource_value_string(M2MSecurity::BootstrapServer) == ""); |
ram54288 | 0:a2cb7295a1f7 | 279 | CHECK(security->resource_value_string(M2MSecurity::ClientHoldOffTime) == ""); |
ram54288 | 0:a2cb7295a1f7 | 280 | CHECK(security->resource_value_string(M2MSecurity::ShortServerID) == ""); |
ram54288 | 0:a2cb7295a1f7 | 281 | CHECK(security->resource_value_string(M2MSecurity::M2MServerSMSNumber) == ""); |
ram54288 | 0:a2cb7295a1f7 | 282 | CHECK(security->resource_value_string(M2MSecurity::SMSSecurityMode) == ""); |
ram54288 | 0:a2cb7295a1f7 | 283 | CHECK(security->resource_value_string(M2MSecurity::SecurityMode) == ""); |
ram54288 | 0:a2cb7295a1f7 | 284 | |
ram54288 | 0:a2cb7295a1f7 | 285 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 286 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 287 | |
ram54288 | 0:a2cb7295a1f7 | 288 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a2cb7295a1f7 | 289 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a2cb7295a1f7 | 290 | } |
ram54288 | 0:a2cb7295a1f7 | 291 | |
ram54288 | 0:a2cb7295a1f7 | 292 | void Test_M2MSecurity::test_resource_value_buffer() |
ram54288 | 0:a2cb7295a1f7 | 293 | { |
ram54288 | 0:a2cb7295a1f7 | 294 | m2mresourceinstance_stub::bool_value = true; |
ram54288 | 0:a2cb7295a1f7 | 295 | |
ram54288 | 0:a2cb7295a1f7 | 296 | uint8_t value[] = {"buffer"}; |
ram54288 | 0:a2cb7295a1f7 | 297 | uint8_t *out_value = NULL; |
ram54288 | 0:a2cb7295a1f7 | 298 | |
ram54288 | 0:a2cb7295a1f7 | 299 | m2mresourceinstance_stub::value = (uint8_t*)malloc((uint32_t)sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 300 | memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 301 | memcpy(m2mresourceinstance_stub::value,value,sizeof(value)); |
ram54288 | 0:a2cb7295a1f7 | 302 | m2mresourceinstance_stub::int_value = (uint16_t)sizeof(value); |
ram54288 | 0:a2cb7295a1f7 | 303 | |
ram54288 | 0:a2cb7295a1f7 | 304 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 305 | "name", |
ram54288 | 0:a2cb7295a1f7 | 306 | "type", |
ram54288 | 0:a2cb7295a1f7 | 307 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 308 | false, |
ram54288 | 0:a2cb7295a1f7 | 309 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 310 | |
ram54288 | 0:a2cb7295a1f7 | 311 | CHECK(security->resource_value_buffer(M2MSecurity::Secretkey,out_value) != 0); |
ram54288 | 0:a2cb7295a1f7 | 312 | CHECK(security->resource_value_buffer(M2MSecurity::ServerPublicKey,out_value) != 0); |
ram54288 | 0:a2cb7295a1f7 | 313 | CHECK(security->resource_value_buffer(M2MSecurity::PublicKey,out_value) != 0); |
ram54288 | 0:a2cb7295a1f7 | 314 | |
ram54288 | 0:a2cb7295a1f7 | 315 | CHECK(security->resource_value_buffer(M2MSecurity::M2MServerUri,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 316 | |
ram54288 | 0:a2cb7295a1f7 | 317 | CHECK(security->resource_value_buffer(M2MSecurity::SMSBindingKey,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 318 | CHECK(security->resource_value_buffer(M2MSecurity::SMSBindingSecretKey,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 319 | CHECK(security->resource_value_buffer(M2MSecurity::BootstrapServer,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 320 | CHECK(security->resource_value_buffer(M2MSecurity::ClientHoldOffTime,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 321 | CHECK(security->resource_value_buffer(M2MSecurity::ShortServerID,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 322 | CHECK(security->resource_value_buffer(M2MSecurity::M2MServerSMSNumber,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 323 | CHECK(security->resource_value_buffer(M2MSecurity::SMSSecurityMode,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 324 | CHECK(security->resource_value_buffer(M2MSecurity::SecurityMode,out_value) == 0); |
ram54288 | 0:a2cb7295a1f7 | 325 | |
ram54288 | 0:a2cb7295a1f7 | 326 | const uint8_t *outvalue = NULL; |
ram54288 | 0:a2cb7295a1f7 | 327 | CHECK(security->resource_value_buffer(M2MSecurity::Secretkey,outvalue) != 0); |
ram54288 | 0:a2cb7295a1f7 | 328 | CHECK(security->resource_value_buffer(M2MSecurity::ServerPublicKey,outvalue) != 0); |
ram54288 | 0:a2cb7295a1f7 | 329 | CHECK(security->resource_value_buffer(M2MSecurity::PublicKey,outvalue) != 0); |
ram54288 | 0:a2cb7295a1f7 | 330 | |
ram54288 | 0:a2cb7295a1f7 | 331 | free(out_value); |
ram54288 | 0:a2cb7295a1f7 | 332 | out_value = NULL; |
ram54288 | 0:a2cb7295a1f7 | 333 | |
ram54288 | 0:a2cb7295a1f7 | 334 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 335 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 336 | |
ram54288 | 0:a2cb7295a1f7 | 337 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a2cb7295a1f7 | 338 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a2cb7295a1f7 | 339 | } |
ram54288 | 0:a2cb7295a1f7 | 340 | |
ram54288 | 0:a2cb7295a1f7 | 341 | void Test_M2MSecurity::test_is_resource_present() |
ram54288 | 0:a2cb7295a1f7 | 342 | { |
ram54288 | 0:a2cb7295a1f7 | 343 | m2mobjectinstance_stub::resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 344 | "name", |
ram54288 | 0:a2cb7295a1f7 | 345 | "type", |
ram54288 | 0:a2cb7295a1f7 | 346 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 347 | false, |
ram54288 | 0:a2cb7295a1f7 | 348 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 349 | |
ram54288 | 0:a2cb7295a1f7 | 350 | CHECK(security->is_resource_present(M2MSecurity::M2MServerUri) == true); |
ram54288 | 0:a2cb7295a1f7 | 351 | |
ram54288 | 0:a2cb7295a1f7 | 352 | delete m2mobjectinstance_stub::resource; |
ram54288 | 0:a2cb7295a1f7 | 353 | m2mobjectinstance_stub::resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 354 | |
ram54288 | 0:a2cb7295a1f7 | 355 | CHECK(security->is_resource_present(M2MSecurity::ClientHoldOffTime) == false); |
ram54288 | 0:a2cb7295a1f7 | 356 | } |
ram54288 | 0:a2cb7295a1f7 | 357 | |
ram54288 | 0:a2cb7295a1f7 | 358 | void Test_M2MSecurity::test_total_resource_count() |
ram54288 | 0:a2cb7295a1f7 | 359 | { |
ram54288 | 0:a2cb7295a1f7 | 360 | M2MResource *res = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 361 | "name", |
ram54288 | 0:a2cb7295a1f7 | 362 | "type", |
ram54288 | 0:a2cb7295a1f7 | 363 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 364 | false, |
ram54288 | 0:a2cb7295a1f7 | 365 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 366 | |
ram54288 | 0:a2cb7295a1f7 | 367 | m2mobjectinstance_stub::resource_list.push_back(res); |
ram54288 | 0:a2cb7295a1f7 | 368 | M2MResource *res2 = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 369 | "name", |
ram54288 | 0:a2cb7295a1f7 | 370 | "type", |
ram54288 | 0:a2cb7295a1f7 | 371 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 372 | false, |
ram54288 | 0:a2cb7295a1f7 | 373 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 374 | |
ram54288 | 0:a2cb7295a1f7 | 375 | m2mobjectinstance_stub::resource_list.push_back(res2); |
ram54288 | 0:a2cb7295a1f7 | 376 | |
ram54288 | 0:a2cb7295a1f7 | 377 | CHECK(security->total_resource_count() == 2); |
ram54288 | 0:a2cb7295a1f7 | 378 | |
ram54288 | 0:a2cb7295a1f7 | 379 | m2mobjectinstance_stub::resource_list.clear(); |
ram54288 | 0:a2cb7295a1f7 | 380 | |
ram54288 | 0:a2cb7295a1f7 | 381 | delete res2; |
ram54288 | 0:a2cb7295a1f7 | 382 | delete res; |
ram54288 | 0:a2cb7295a1f7 | 383 | } |
ram54288 | 0:a2cb7295a1f7 | 384 | |
ram54288 | 0:a2cb7295a1f7 | 385 | void Test_M2MSecurity::test_m2m_server_constructor() |
ram54288 | 0:a2cb7295a1f7 | 386 | { |
ram54288 | 0:a2cb7295a1f7 | 387 | m2mobjectinstance_stub::create_resource = new M2MResource(*m2mobject_stub::inst, |
ram54288 | 0:a2cb7295a1f7 | 388 | "name", |
ram54288 | 0:a2cb7295a1f7 | 389 | "type", |
ram54288 | 0:a2cb7295a1f7 | 390 | M2MResourceInstance::STRING, |
ram54288 | 0:a2cb7295a1f7 | 391 | false, |
ram54288 | 0:a2cb7295a1f7 | 392 | "name"); |
ram54288 | 0:a2cb7295a1f7 | 393 | |
ram54288 | 0:a2cb7295a1f7 | 394 | M2MSecurity* sec = new M2MSecurity(M2MSecurity::M2MServer); |
ram54288 | 0:a2cb7295a1f7 | 395 | CHECK(M2MSecurity::M2MServer == sec->server_type()); |
ram54288 | 0:a2cb7295a1f7 | 396 | |
ram54288 | 0:a2cb7295a1f7 | 397 | delete sec; |
ram54288 | 0:a2cb7295a1f7 | 398 | delete m2mobjectinstance_stub::create_resource; |
ram54288 | 0:a2cb7295a1f7 | 399 | m2mobjectinstance_stub::create_resource = NULL; |
ram54288 | 0:a2cb7295a1f7 | 400 | } |
ram54288 | 0:a2cb7295a1f7 | 401 | |
ram54288 | 0:a2cb7295a1f7 | 402 | void Test_M2MSecurity::test_server_type() |
ram54288 | 0:a2cb7295a1f7 | 403 | { |
ram54288 | 0:a2cb7295a1f7 | 404 | CHECK(M2MSecurity::Bootstrap ==security->server_type()); |
ram54288 | 0:a2cb7295a1f7 | 405 | } |