Search in sources :

Example 51 with IotHubConnectionString

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);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 52 with IotHubConnectionString

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);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 53 with IotHubConnectionString

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());
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 54 with IotHubConnectionString

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);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 55 with IotHubConnectionString

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);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Aggregations

IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)64 Test (org.junit.Test)63 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)31 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)27 NonStrictExpectations (mockit.NonStrictExpectations)9 IotHubSSLContext (com.microsoft.azure.sdk.iot.device.IotHubSSLContext)2 Message (com.microsoft.azure.sdk.iot.device.Message)1 MessageCallback (com.microsoft.azure.sdk.iot.device.MessageCallback)1 MessageType (com.microsoft.azure.sdk.iot.device.MessageType)1 Date (java.util.Date)1