Skip to content

Commit

Permalink
test: skip HTTP tests that use httpbin
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jul 21, 2023
1 parent 1fd9a64 commit d0bf7ad
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 68 deletions.
99 changes: 52 additions & 47 deletions test/binding_http/http_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ void main() {
expect(customServer2.scheme, 'https');
});

test('HTTP Security Schemes', () async {
const username = 'username';
const password = 'password';
const token = 'thisIsTheMostAwesomeTokenEver!';

// TODO(JKRhb): Does not have an effect in the TD yet (and is negotiated
// automatically by http_auth instead)
const qop = 'auth-int';

const thingDescriptionJson = '''
test(
'HTTP Security Schemes',
() async {
const username = 'username';
const password = 'password';
const token = 'thisIsTheMostAwesomeTokenEver!';

// TODO(JKRhb): Does not have an effect in the TD yet (and is negotiated
// automatically by http_auth instead)
const qop = 'auth-int';

const thingDescriptionJson = '''
{
"@context": ["http://www.w3.org/ns/td"],
"title": "Test Thing",
Expand Down Expand Up @@ -101,46 +103,49 @@ void main() {
}
''';

final parsedTd = ThingDescription(thingDescriptionJson);

final Map<String, BasicCredentials> basicCredentialsStore = {
'httpbin.org': BasicCredentials(username, password),
};

final Map<String, DigestCredentials> digestCredentialsStore = {
'httpbin.org': DigestCredentials(username, password),
};

final Map<String, BearerCredentials> bearerCredentialsStore = {
'httpbin.org': BearerCredentials(token),
};
final parsedTd = ThingDescription(thingDescriptionJson);

final clientSecurityProvider = ClientSecurityProvider(
basicCredentialsCallback: (uri, form, [invalidCredentials]) async {
return basicCredentialsStore[uri.host];
},
digestCredentialsCallback: (uri, form, [invalidCredentials]) async =>
digestCredentialsStore[uri.host],
bearerCredentialsCallback: (uri, form, [invalidCredentials]) async =>
bearerCredentialsStore[uri.host],
);

final servient = Servient(clientSecurityProvider: clientSecurityProvider)
..addClientFactory(HttpClientFactory());
final wot = await servient.start();
final Map<String, BasicCredentials> basicCredentialsStore = {
'httpbin.org': BasicCredentials(username, password),
};

final consumedThing = await wot.consume(parsedTd);
final result = await consumedThing.readProperty('status');
final value = await result.value();
expect(value, {'authenticated': true, 'user': username});
final Map<String, DigestCredentials> digestCredentialsStore = {
'httpbin.org': DigestCredentials(username, password),
};

// final result2 = await consumedThing.readProperty('status2');
// final value2 = await result2.value();
// expect(value2, {'authenticated': true, 'user': username});
final Map<String, BearerCredentials> bearerCredentialsStore = {
'httpbin.org': BearerCredentials(token),
};

final result3 = await consumedThing.readProperty('status3');
final value3 = await result3.value();
expect(value3, {'authenticated': true, 'token': token});
});
final clientSecurityProvider = ClientSecurityProvider(
basicCredentialsCallback: (uri, form, [invalidCredentials]) async {
return basicCredentialsStore[uri.host];
},
digestCredentialsCallback: (uri, form, [invalidCredentials]) async =>
digestCredentialsStore[uri.host],
bearerCredentialsCallback: (uri, form, [invalidCredentials]) async =>
bearerCredentialsStore[uri.host],
);

final servient =
Servient(clientSecurityProvider: clientSecurityProvider)
..addClientFactory(HttpClientFactory());
final wot = await servient.start();

final consumedThing = await wot.consume(parsedTd);
final result = await consumedThing.readProperty('status');
final value = await result.value();
expect(value, {'authenticated': true, 'user': username});

// final result2 = await consumedThing.readProperty('status2');
// final value2 = await result2.value();
// expect(value2, {'authenticated': true, 'user': username});

final result3 = await consumedThing.readProperty('status3');
final value3 = await result3.value();
expect(value3, {'authenticated': true, 'token': token});
},
skip: true,
);
});
}
46 changes: 25 additions & 21 deletions test/core/consumed_thing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ void main() {
});
});

test('Use of URI Template Variables', () async {
const thingDescriptionJson = '''
test(
'Use of URI Template Variables',
() async {
const thingDescriptionJson = '''
{
"@context": ["http://www.w3.org/ns/td"],
"title": "Test Thing",
Expand Down Expand Up @@ -280,28 +282,30 @@ void main() {
}
''';

final parsedTd = ThingDescription(thingDescriptionJson);
final parsedTd = ThingDescription(thingDescriptionJson);

final servient = Servient()..addClientFactory(HttpClientFactory());
final wot = await servient.start();
final servient = Servient()..addClientFactory(HttpClientFactory());
final wot = await servient.start();

final uriVariables = {'value': 'SFRUUEJJTiBpcyBhd2Vzb21l'};
final interactionOptions = InteractionOptions(uriVariables: uriVariables);
final uriVariables = {'value': 'SFRUUEJJTiBpcyBhd2Vzb21l'};
final interactionOptions = InteractionOptions(uriVariables: uriVariables);

final consumedThing = await wot.consume(parsedTd);
final result =
await consumedThing.readProperty('status', interactionOptions);
final value = await result.value();
expect(value, 'HTTPBIN is awesome');
final consumedThing = await wot.consume(parsedTd);
final result =
await consumedThing.readProperty('status', interactionOptions);
final value = await result.value();
expect(value, 'HTTPBIN is awesome');

// status2 expects an integer instead of a String and throws an error if the
// same value is provided as an input
expect(
consumedThing.readProperty('status2', interactionOptions),
throwsA(const TypeMatcher<ValidationException>()),
);
// status2 expects an integer instead of a String and throws an error if
// the same value is provided as an input
expect(
consumedThing.readProperty('status2', interactionOptions),
throwsA(const TypeMatcher<ValidationException>()),
);

await servient.shutdown();
expect(servient.destroyConsumedThing(parsedTd.identifier), false);
});
await servient.shutdown();
expect(servient.destroyConsumedThing(parsedTd.identifier), false);
},
skip: true, // TODO: Replace with test with local server
);
}

0 comments on commit d0bf7ad

Please sign in to comment.