use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method propertyAccess.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_001: [Provide access to the following properties: policyName, key, token]
@Test
public void propertyAccess() {
// Arrange
String policyName = "accessKeyPolicy";
String key = "11223344556677889900";
// Act
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(policyName, key);
// Assert
assertEquals(policyName, auth.getPolicyName());
assertEquals(key, auth.getKey());
}
use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method populate_input_null.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_002: [The function shall throw IllegalArgumentException if the input object is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void populate_input_null() throws Exception {
// Arrange
String newPolicyName = "XXX";
String newPolicyKey = "YYY";
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
// Act
Deencapsulation.invoke(auth, "populate", IotHubConnectionString.class);
}
use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method populate_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_003: [The function shall save the policyName and policyKey to the target object]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_004: [The function shall set the access signature (token) to null]
@Test
public void populate_good_case() throws Exception {
// Arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
String iotHubName = "b.c.d";
String hostName = "HOSTNAME." + iotHubName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
String newPolicyName = "XXX";
String newPolicyKey = "YYY";
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
// Act
Deencapsulation.invoke(auth, "populate", iotHubConnectionString);
// Assert
assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessKey());
assertEquals(null, iotHubConnectionString.getSharedAccessSignature());
// Act
Deencapsulation.invoke(auth, "setPolicyName", policyName);
Deencapsulation.invoke(auth, "setKey", sharedAccessKey);
// Assert
assertEquals(policyName, auth.getPolicyName());
assertEquals(sharedAccessKey, auth.getKey());
}
use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method setAuthenticationMethod_good_case_key.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_023: [The function shall populate and set the authenticationMethod on the given target iotHubConnectionString object]
@Test
public void setAuthenticationMethod_good_case_key() throws Exception {
// Arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
String iotHubName = "b.c.d";
String hostName = "HOSTNAME." + iotHubName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
String newPolicyName = "XXX";
String newPolicyKey = "YYY";
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
new Expectations() {
{
Deencapsulation.invoke(iotHubConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
}
};
// Act
Deencapsulation.invoke(iotHubConnectionString, "setAuthenticationMethod", auth, iotHubConnectionString);
// Assert
assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessKey());
assertEquals(null, iotHubConnectionString.getSharedAccessSignature());
}
Aggregations