use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method IotHubConnectionStringSharedAccessTokenSuccess.
/* Tests_SRS_IOTHUB_CONNECTIONSTRING_21_010: [The constructor shall interpret the connection string as a set of key-value pairs delimited by ';', with keys and values separated by '='.] */
/* Tests_SRS_IOTHUB_CONNECTIONSTRING_21_015: [The constructor shall save the shared access token as the value of 'sharedAccessToken' in the connection string.] */
@Test
public void IotHubConnectionStringSharedAccessTokenSuccess() throws ClassNotFoundException {
// arrange
final String connString = "HostName=" + VALID_HOSTNAME + ";CredentialType=SharedAccessKey;CredentialScope=Device;" + "DeviceId=" + VALID_DEVICEID + ";SharedAccessSignature=" + VALID_SHARED_ACCESS_TOKEN + ";";
// act
Object iotHubConnectionString = Deencapsulation.newInstance(Class.forName(IOTHUB_CONNECTION_STRING_CLASS), new Class[] { String.class }, connString);
// assert
assertConnectionString(iotHubConnectionString, VALID_HOSTNAME, VALID_DEVICEID, null, VALID_SHARED_ACCESS_TOKEN);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method IotHubConnectionStringExpiredConnectionStringThrowsSecurityException.
/* Tests_SRS_IOTHUB_CONNECTIONSTRING_34_035: [If the connection string contains an expired SAS Token, throw a SecurityException] */
@Test(expected = SecurityException.class)
public void IotHubConnectionStringExpiredConnectionStringThrowsSecurityException(@Mocked final IotHubSasToken iotHubSasToken) throws SecurityException, ClassNotFoundException {
// arrange
final String connString = "HostName=" + VALID_HOSTNAME + ";CredentialType=SharedAccessKey;CredentialScope=Device;" + "DeviceId=" + VALID_DEVICEID + ";SharedAccessSignature=" + EXPIRED_SHARED_ACCESS_TOKEN + ";";
new NonStrictExpectations() {
{
IotHubSasToken.isExpired(anyString);
result = true;
}
};
// act
Object iotHubConnectionString = Deencapsulation.newInstance(Class.forName(IOTHUB_CONNECTION_STRING_CLASS), new Class[] { String.class }, connString);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method ConstructorSavesAttributesCaseInsensitively.
// Tests_SRS_IOTHUB_CONNECTIONSTRING_34_041: [The constructor shall save the gateway host name as the value of 'GatewayHostName' in the connection string.]
// Tests_SRS_IOTHUB_CONNECTIONSTRING_34_043: [The getGatewayHostName shall return the stored gateway host name.]
@Test
public void ConstructorSavesAttributesCaseInsensitively() throws URISyntaxException {
// arrange
final String connString = "HOSTNAME=" + VALID_HOSTNAME + ";CredentialType=SharedAccessKey;" + "DeVicEid=" + VALID_DEVICEID + ";SharedACCESSKey=" + VALID_SHARED_ACCESS_KEY + ";MoDuLeId=" + VALID_MODULEID + ";GATeWayHOstnaMe=" + VALID_GATEWAYHOSTNAME + ";";
// act
IotHubConnectionString connectionString = new IotHubConnectionString(connString);
// assert
assertEquals(VALID_MODULEID, connectionString.getModuleId());
assertEquals(VALID_HOSTNAME, connectionString.getHostName());
assertEquals(VALID_GATEWAYHOSTNAME, connectionString.getGatewayHostName());
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method isUsingX509WorksWhenFalse.
// Tests_SRS_IOTHUB_CONNECTIONSTRING_34_039: [If the connection string passed in the constructor contains the string 'x509=true' then this function shall return true.]
@Test
public void isUsingX509WorksWhenFalse() {
// arrange
final String connString = "HostName=" + VALID_HOSTNAME + ";CredentialType=SharedAccessKey;CredentialScope=Device;" + "DeviceId=" + VALID_DEVICEID + ";SharedAccessSignature=" + VALID_SHARED_ACCESS_TOKEN + ";";
IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class }, connString);
// act
boolean isUsingX509 = iotHubConnectionString.isUsingX509();
// assert
assertFalse(isUsingX509);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method doesNotSetSASTokenWithoutSe.
// Tests_SRS_IOTHUBSASTOKEN_25_008: [**The required format for the SAS Token shall be verified and IllegalArgumentException is thrown if unmatched.**]**
// Tests_SRS_IOTHUBSASTOKEN_11_001: [**The SAS token shall have the format `SharedAccessSignature sig=<signature >&se=<expiryTime>&sr=<resourceURI>`. The params can be in any order.**]**
@Test(expected = IllegalArgumentException.class)
public void doesNotSetSASTokenWithoutSe() throws URISyntaxException {
String sastoken = "SharedAccessSignature sr=blah&sig=blah";
final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", null, sastoken);
IotHubSasToken token = Deencapsulation.newInstance(IotHubSasToken.class, new Class[] { String.class, String.class, String.class, String.class, long.class }, iotHubConnectionString.getHostName(), iotHubConnectionString.getDeviceId(), iotHubConnectionString.getSharedAccessKey(), iotHubConnectionString.getSharedAccessToken(), 0);
}
Aggregations