Skip to content

Commit 7d0c4f6

Browse files
authored
Update WebPushTest and SubscriptionPublicKey to use VAPID keys (#65)
1 parent bdc01b5 commit 7d0c4f6

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

src/main/kotlin/at/bitfire/dav4jvm/property/push/ServerPublicKey.kt renamed to src/main/kotlin/at/bitfire/dav4jvm/property/push/SubscriptionPublicKey.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import at.bitfire.dav4jvm.XmlReader
66
import org.xmlpull.v1.XmlPullParser
77

88
/**
9-
* Represents a [NS_WEBDAV_PUSH]`:server-public-key` property.
9+
* Represents a [NS_WEBDAV_PUSH]`:subscription-public-key` property.
1010
*
1111
* Experimental! See https://github.com/bitfireAT/webdav-push/
1212
*/
13-
data class ServerPublicKey(
13+
data class SubscriptionPublicKey(
1414
val type: String? = null,
1515
val key: String? = null
1616
): Property {
1717

1818
companion object {
1919

2020
@JvmField
21-
val NAME = Property.Name(NS_WEBDAV_PUSH, "server-public-key")
21+
val NAME = Property.Name(NS_WEBDAV_PUSH, "subscription-public-key")
2222

2323
}
2424

@@ -27,8 +27,8 @@ data class ServerPublicKey(
2727

2828
override fun getName() = NAME
2929

30-
override fun create(parser: XmlPullParser): ServerPublicKey {
31-
return ServerPublicKey(
30+
override fun create(parser: XmlPullParser): SubscriptionPublicKey {
31+
return SubscriptionPublicKey(
3232
type = parser.getAttributeValue(null, "type"),
3333
key = XmlReader(parser).readText()
3434
)

src/main/kotlin/at/bitfire/dav4jvm/property/push/ClientPublicKey.kt renamed to src/main/kotlin/at/bitfire/dav4jvm/property/push/VapidPublicKey.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import at.bitfire.dav4jvm.XmlReader
66
import org.xmlpull.v1.XmlPullParser
77

88
/**
9-
* Represents a [NS_WEBDAV_PUSH]`:client-public-key` property.
9+
* Represents a [NS_WEBDAV_PUSH]`:vapid-public-key` property.
1010
*
1111
* Experimental! See https://github.com/bitfireAT/webdav-push/
1212
*/
13-
data class ClientPublicKey(
13+
data class VapidPublicKey(
1414
val type: String? = null,
1515
val key: String? = null
1616
): Property {
1717

1818
companion object {
1919

2020
@JvmField
21-
val NAME = Property.Name(NS_WEBDAV_PUSH, "client-public-key")
21+
val NAME = Property.Name(NS_WEBDAV_PUSH, "vapid-public-key")
2222

2323
}
2424

@@ -27,8 +27,8 @@ data class ClientPublicKey(
2727

2828
override fun getName() = NAME
2929

30-
override fun create(parser: XmlPullParser): ClientPublicKey {
31-
return ClientPublicKey(
30+
override fun create(parser: XmlPullParser): VapidPublicKey {
31+
return VapidPublicKey(
3232
type = parser.getAttributeValue(null, "type"),
3333
key = XmlReader(parser).readText()
3434
)

src/main/kotlin/at/bitfire/dav4jvm/property/push/WebPush.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,34 @@ import org.xmlpull.v1.XmlPullParser
1010
* Experimental! See https://github.com/bitfireAT/webdav-push/
1111
*/
1212
data class WebPush(
13-
val serverPublicKey: ServerPublicKey? = null
14-
): PushTransport {
13+
val vapidPublicKey: VapidPublicKey? = null
14+
) : PushTransport {
1515

1616
companion object {
1717
@JvmField
1818
val NAME = Property.Name(NS_WEBDAV_PUSH, "web-push")
1919
}
2020

2121

22-
object Factory: PropertyFactory {
22+
object Factory : PropertyFactory {
2323

2424
override fun getName(): Property.Name = NAME
2525

2626
override fun create(parser: XmlPullParser): WebPush {
27-
var serverPublicKey: ServerPublicKey? = null
27+
var vapidPublicKey: VapidPublicKey? = null
2828
val depth = parser.depth
2929
var eventType = parser.eventType
3030
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
3131
if (eventType == XmlPullParser.START_TAG && parser.namespace == NS_WEBDAV_PUSH) {
3232
when (parser.name) {
33-
ServerPublicKey.NAME.name
34-
-> serverPublicKey = ServerPublicKey.Factory.create(parser)
33+
VapidPublicKey.NAME.name -> vapidPublicKey = VapidPublicKey.Factory.create(parser)
3534
}
3635
}
3736
eventType = parser.next()
3837
}
39-
return WebPush(serverPublicKey)
38+
return WebPush(vapidPublicKey)
4039
}
4140

4241
}
4342

44-
}
43+
}

src/main/kotlin/at/bitfire/dav4jvm/property/push/WebPushSubscription.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.xmlpull.v1.XmlPullParser
1818
*/
1919
data class WebPushSubscription(
2020
val pushResource: PushResource? = null,
21-
val clientPublicKey: ClientPublicKey? = null,
21+
val subscriptionPublicKey: SubscriptionPublicKey? = null,
2222
val authSecret: AuthSecret? = null
2323
): Property {
2424

@@ -43,7 +43,7 @@ data class WebPushSubscription(
4343
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) {
4444
when (parser.propertyName()) {
4545
PushResource.NAME -> subscription = subscription.copy(pushResource = PushResource.Factory.create(parser))
46-
ClientPublicKey.NAME -> subscription = subscription.copy(clientPublicKey = ClientPublicKey.Factory.create(parser))
46+
SubscriptionPublicKey.NAME -> subscription = subscription.copy(subscriptionPublicKey = SubscriptionPublicKey.Factory.create(parser))
4747
AuthSecret.NAME -> subscription = subscription.copy(authSecret = AuthSecret.Factory.create(parser))
4848
}
4949
}

src/test/kotlin/at/bitfire/dav4jvm/property/push/WebPushTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WebPushTest: PropertyTest() {
1616
" <subscription>" +
1717
" <web-push-subscription>\n" +
1818
" <push-resource>https://up.example.net/yohd4yai5Phiz1wi</push-resource>\n" +
19-
" <client-public-key type=\"p256dh\">BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4</client-public-key>\n" +
19+
" <subscription-public-key type=\"p256dh\">BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4</subscription-public-key>\n" +
2020
" <auth-secret>BTBZMqHH6r4Tts7J_aSIgg</auth-secret>" +
2121
" </web-push-subscription>\n" +
2222
" </subscription>" +
@@ -28,7 +28,7 @@ class WebPushTest: PropertyTest() {
2828
assertEquals("https://up.example.net/yohd4yai5Phiz1wi", subscription?.pushResource?.uri?.toString())
2929
assertEquals("BTBZMqHH6r4Tts7J_aSIgg", subscription?.authSecret?.secret)
3030

31-
val publicKey = subscription?.clientPublicKey
31+
val publicKey = subscription?.subscriptionPublicKey
3232
assertEquals("p256dh", publicKey?.type)
3333
assertEquals("BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4", publicKey?.key)
3434
}
@@ -39,7 +39,7 @@ class WebPushTest: PropertyTest() {
3939
"<transports xmlns=\"$NS_WEBDAV_PUSH\">" +
4040
" <something><else/></something>" +
4141
" <web-push>" +
42-
" <server-public-key type=\"p256dh\">BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4</server-public-key>" +
42+
" <vapid-public-key type=\"p256dh\">BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4</vapid-public-key>" +
4343
" </web-push>" +
4444
"</transports>" +
4545
"<topic xmlns=\"$NS_WEBDAV_PUSH\">SomeTopic</topic>")
@@ -48,7 +48,7 @@ class WebPushTest: PropertyTest() {
4848
assertEquals(setOf(
4949
// something else is ignored because it's not a recognized transport
5050
WebPush(
51-
ServerPublicKey(
51+
VapidPublicKey(
5252
type = "p256dh",
5353
key = "BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4"
5454
)

0 commit comments

Comments
 (0)