use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method doesNotSetSASTokenWithoutSr.
// 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 doesNotSetSASTokenWithoutSr() throws URISyntaxException {
String sastoken = "SharedAccessSignature sig=blah&se=" + Long.MAX_VALUE;
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);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method setValidSASTokenCorrectlyDespiteFurtherReorganizedSignature.
// 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
public void setValidSASTokenCorrectlyDespiteFurtherReorganizedSignature() throws URISyntaxException {
// Typical order of fields in SAS token is sr=<>&sig=<>&se=<>, however these should be able to be reorganized freely
// This test tries se=<>&sig=<>&sr=<>
String sastoken = "SharedAccessSignature se=" + Long.MAX_VALUE + "&sig=sigValue&sr=srValue";
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, String.class, long.class }, iotHubConnectionString.getHostName(), iotHubConnectionString.getDeviceId(), iotHubConnectionString.getSharedAccessKey(), iotHubConnectionString.getSharedAccessToken(), iotHubConnectionString.getModuleId(), 0);
String tokenStr = token.toString();
assertEquals(tokenStr, sastoken);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method emptyResourceURIFieldValueThrowsIllegalArgumentException.
@Test(expected = IllegalArgumentException.class)
public void emptyResourceURIFieldValueThrowsIllegalArgumentException() {
Long expiryTime = Long.MAX_VALUE;
String sastoken = "SharedAccessSignature sr=&sig=sigValue&se=" + expiryTime;
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);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method sasTokenHasCorrectFormat.
// 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
public void sasTokenHasCorrectFormat() throws URISyntaxException {
final long expiryTime = 100;
final String signature = "sample-sig";
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", "sample-device-key", null);
new NonStrictExpectations() {
{
mockSig.toString();
result = signature;
}
};
IotHubSasToken token = Deencapsulation.newInstance(IotHubSasToken.class, new Class[] { String.class, String.class, String.class, String.class, String.class, long.class }, iotHubConnectionString.getHostName(), iotHubConnectionString.getDeviceId(), iotHubConnectionString.getSharedAccessKey(), iotHubConnectionString.getSharedAccessToken(), iotHubConnectionString.getModuleId(), expiryTime);
String tokenStr = token.toString();
// assert that sig, se and sr exist in the token in any order.
assertThat(tokenStr.indexOf("SharedAccessSignature "), is(not(-1)));
assertThat(tokenStr.indexOf("sig="), is(not(-1)));
assertThat(tokenStr.indexOf("se="), is(not(-1)));
assertThat(tokenStr.indexOf("sr="), is(not(-1)));
}
Aggregations