-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail when pushbullet credentials are not valid
Do not try to authenticate indefinitely when provided access token is not valid. https://github.com/square/okhttp/wiki/Recipes#handling-authentication Fixes #6
- Loading branch information
Showing
5 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...n/src/test/groovy/fr/jcgay/notification/notifier/pushbullet/PushbulletNotifierSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fr.jcgay.notification.notifier.pushbullet | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule | ||
import fr.jcgay.notification.Application | ||
import fr.jcgay.notification.Icon | ||
import fr.jcgay.notification.Notification | ||
import org.junit.Rule | ||
import spock.lang.Specification | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.* | ||
import static fr.jcgay.notification.Notification.Level.ERROR | ||
|
||
class PushbulletNotifierSpec extends Specification { | ||
|
||
@Rule | ||
WireMockRule wireMock = new WireMockRule() | ||
|
||
def "should fail when credentials are not valid"() { | ||
given: | ||
def icon = Icon.create(new URL('file:/icon.png'), 'icon') | ||
def application = Application.builder('id', 'name', icon).build() | ||
Properties configuration = [ | ||
'notifier.pushbullet.apikey':'access-token-not-valid', | ||
] | ||
|
||
and: | ||
def pushbullet = new PushbulletNotifier(application, PushbulletConfiguration.create(configuration), "http://localhost:${wireMock.port()}/pushes") | ||
pushbullet.init() | ||
|
||
and: | ||
wireMock.stubFor(post(urlEqualTo("/pushes")).willReturn(aResponse().withStatus(401))) | ||
|
||
when: | ||
pushbullet.send(Notification.builder('title', 'message', icon) | ||
.subtitle('subtitle') | ||
.level(ERROR) | ||
.build()) | ||
|
||
then: | ||
def result = thrown(PushbulletNotificationException) | ||
result.message == 'Pushbullet notification has failed, [401] - [Unauthorized]\n\nCheck your configuration at: https://github.com/jcgay/send-notification/wiki/Pushbullet' | ||
} | ||
} |