Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
dav4jvm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
bitfire web engineering
dav4jvm
Commits
1169e150
Commit
1169e150
authored
Mar 12, 2018
by
Ricki Hirner
🐑
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update okhttp, tests in Kotlin, refactoring
parent
568f0285
Pipeline
#18748357
passed with stages
in 3 minutes and 50 seconds
Changes
29
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
883 additions
and
493 deletions
+883
-493
build.gradle
build.gradle
+4
-4
src/androidTest/java/at/bitfire/dav4android/DavResourceTest.kt
...ndroidTest/java/at/bitfire/dav4android/DavResourceTest.kt
+234
-250
src/main/java/at/bitfire/dav4android/BasicDigestAuthHandler.kt
...ain/java/at/bitfire/dav4android/BasicDigestAuthHandler.kt
+2
-2
src/main/java/at/bitfire/dav4android/Constants.kt
src/main/java/at/bitfire/dav4android/Constants.kt
+0
-1
src/main/java/at/bitfire/dav4android/DavAddressBook.kt
src/main/java/at/bitfire/dav4android/DavAddressBook.kt
+0
-5
src/main/java/at/bitfire/dav4android/DavCalendar.kt
src/main/java/at/bitfire/dav4android/DavCalendar.kt
+0
-3
src/main/java/at/bitfire/dav4android/DavCollection.kt
src/main/java/at/bitfire/dav4android/DavCollection.kt
+8
-2
src/main/java/at/bitfire/dav4android/DavResource.kt
src/main/java/at/bitfire/dav4android/DavResource.kt
+6
-6
src/main/java/at/bitfire/dav4android/HttpUtils.kt
src/main/java/at/bitfire/dav4android/HttpUtils.kt
+0
-2
src/main/java/at/bitfire/dav4android/Property.kt
src/main/java/at/bitfire/dav4android/Property.kt
+5
-5
src/main/java/at/bitfire/dav4android/PropertyCollection.kt
src/main/java/at/bitfire/dav4android/PropertyCollection.kt
+8
-9
src/main/java/at/bitfire/dav4android/PropertyFactory.kt
src/main/java/at/bitfire/dav4android/PropertyFactory.kt
+4
-1
src/main/java/at/bitfire/dav4android/QuotedStringUtils.kt
src/main/java/at/bitfire/dav4android/QuotedStringUtils.kt
+3
-12
src/main/java/at/bitfire/dav4android/UrlUtils.kt
src/main/java/at/bitfire/dav4android/UrlUtils.kt
+0
-4
src/main/java/at/bitfire/dav4android/XmlUtils.kt
src/main/java/at/bitfire/dav4android/XmlUtils.kt
+5
-8
src/main/java/at/bitfire/dav4android/exception/DavException.kt
...ain/java/at/bitfire/dav4android/exception/DavException.kt
+4
-1
src/main/java/at/bitfire/dav4android/exception/HttpException.kt
...in/java/at/bitfire/dav4android/exception/HttpException.kt
+4
-2
src/main/java/at/bitfire/dav4android/exception/InvalidDavResponseException.kt
...fire/dav4android/exception/InvalidDavResponseException.kt
+4
-1
src/main/java/at/bitfire/dav4android/exception/UnsupportedDavException.kt
.../bitfire/dav4android/exception/UnsupportedDavException.kt
+1
-1
src/main/java/at/bitfire/dav4android/property/GetETag.kt
src/main/java/at/bitfire/dav4android/property/GetETag.kt
+1
-1
src/main/java/at/bitfire/dav4android/property/ResourceType.kt
...main/java/at/bitfire/dav4android/property/ResourceType.kt
+5
-5
src/main/java/at/bitfire/dav4android/property/SupportedReportSet.kt
...ava/at/bitfire/dav4android/property/SupportedReportSet.kt
+2
-2
src/test/java/at/bitfire/dav4android/BasicDigestAuthHandlerTest.kt
...java/at/bitfire/dav4android/BasicDigestAuthHandlerTest.kt
+268
-0
src/test/java/at/bitfire/dav4android/HttpUtilsTest.java
src/test/java/at/bitfire/dav4android/HttpUtilsTest.java
+0
-144
src/test/java/at/bitfire/dav4android/HttpUtilsTest.kt
src/test/java/at/bitfire/dav4android/HttpUtilsTest.kt
+140
-0
src/test/java/at/bitfire/dav4android/QuotedStringUtilsTest.kt
...test/java/at/bitfire/dav4android/QuotedStringUtilsTest.kt
+19
-22
src/test/java/at/bitfire/dav4android/UrlUtilsTest.kt
src/test/java/at/bitfire/dav4android/UrlUtilsTest.kt
+56
-0
src/test/java/at/bitfire/dav4android/exception/HttpExceptionTest.kt
...ava/at/bitfire/dav4android/exception/HttpExceptionTest.kt
+40
-0
src/test/java/at/bitfire/dav4android/exception/ServiceUnavailableExceptionTest.kt
.../dav4android/exception/ServiceUnavailableExceptionTest.kt
+60
-0
No files found.
build.gradle
View file @
1169e150
buildscript
{
ext
.
kotlin_version
=
'1.2.
21
'
ext
.
kotlin_version
=
'1.2.
30
'
ext
.
dokka_version
=
'0.9.15'
repositories
{
...
...
@@ -52,12 +52,12 @@ android {
dependencies
{
compile
"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile
'com.squareup.okhttp3:okhttp:3.
9.1
'
compile
'com.squareup.okhttp3:okhttp:3.
10.0
'
androidTestCompile
'com.squareup.okhttp3:mockwebserver:3.
9.1
'
androidTestCompile
'com.squareup.okhttp3:mockwebserver:3.
10.0
'
androidTestCompile
'com.android.support.test:runner:1.0.1'
testCompile
"org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile
'junit:junit:4.12'
testCompile
'com.squareup.okhttp3:mockwebserver:3.
9.1
'
testCompile
'com.squareup.okhttp3:mockwebserver:3.
10.0
'
}
src/androidTest/java/at/bitfire/dav4android/DavResourceTest.
java
→
src/androidTest/java/at/bitfire/dav4android/DavResourceTest.
kt
View file @
1169e150
This diff is collapsed.
Click to expand it.
src/main/java/at/bitfire/dav4android/BasicDigestAuthHandler.kt
View file @
1169e150
...
...
@@ -40,8 +40,8 @@ class BasicDigestAuthHandler(
private
val
HEADER_AUTHORIZATION
=
"Authorization"
// cached digest parameters
@JvmField
var
clientNonce
=
h
(
UUID
.
randomUUID
().
toString
())
@JvmField
var
nonceCount
=
AtomicInteger
(
1
)
var
clientNonce
=
h
(
UUID
.
randomUUID
().
toString
())
var
nonceCount
=
AtomicInteger
(
1
)
fun
quotedString
(
s
:
String
)
=
"\""
+
s
.
replace
(
"\""
,
"\\\""
)
+
"\""
fun
h
(
data
:
String
)
=
ByteString
.
of
(
ByteBuffer
.
wrap
(
data
.
toByteArray
())).
md5
().
hex
()
!!
...
...
src/main/java/at/bitfire/dav4android/Constants.kt
View file @
1169e150
...
...
@@ -12,7 +12,6 @@ import java.util.logging.Logger
object
Constants
{
@JvmField
var
log
=
Logger
.
getLogger
(
"dav4android"
)
!!
}
\ No newline at end of file
src/main/java/at/bitfire/dav4android/DavAddressBook.kt
View file @
1169e150
...
...
@@ -22,10 +22,7 @@ class DavAddressBook @JvmOverloads constructor(
):
DavCollection
(
httpClient
,
location
,
log
)
{
companion
object
{
@JvmField
val
MIME_VCARD3_UTF8
=
MediaType
.
parse
(
"text/vcard;charset=utf-8"
)
@JvmField
val
MIME_VCARD4
=
MediaType
.
parse
(
"text/vcard;version=4.0"
)
}
...
...
@@ -36,7 +33,6 @@ class DavAddressBook @JvmOverloads constructor(
* @throws HttpException on HTTP error
* @throws DavException on DAV error
*/
@Throws
(
IOException
::
class
,
HttpException
::
class
,
DavException
::
class
)
fun
addressbookQuery
()
{
/* <!ELEMENT addressbook-query ((DAV:allprop |
DAV:propname |
...
...
@@ -78,7 +74,6 @@ class DavAddressBook @JvmOverloads constructor(
* @throws HttpException on HTTP error
* @throws DavException on DAV error
*/
@Throws
(
IOException
::
class
,
HttpException
::
class
,
DavException
::
class
)
fun
multiget
(
urls
:
List
<
HttpUrl
>,
vCard4
:
Boolean
)
{
/* <!ELEMENT addressbook-multiget ((DAV:allprop |
DAV:propname |
...
...
src/main/java/at/bitfire/dav4android/DavCalendar.kt
View file @
1169e150
...
...
@@ -24,7 +24,6 @@ class DavCalendar @JvmOverloads constructor(
):
DavCollection
(
httpClient
,
location
,
log
)
{
companion
object
{
@JvmField
val
MIME_ICALENDAR
=
MediaType
.
parse
(
"text/calendar"
)
val
MIME_ICALENDAR_UTF8
=
MediaType
.
parse
(
"text/calendar;charset=utf-8"
)
}
...
...
@@ -38,7 +37,6 @@ class DavCalendar @JvmOverloads constructor(
* @throws HttpException on HTTP error
* @throws DavException on DAV error
*/
@Throws
(
IOException
::
class
,
HttpException
::
class
,
DavException
::
class
)
fun
calendarQuery
(
component
:
String
,
start
:
Date
?,
end
:
Date
?)
{
/* <!ELEMENT calendar-query ((DAV:allprop |
DAV:propname |
...
...
@@ -100,7 +98,6 @@ class DavCalendar @JvmOverloads constructor(
* @throws HttpException on HTTP error
* @throws DavException on DAV error
*/
@Throws
(
IOException
::
class
,
HttpException
::
class
,
DavException
::
class
)
fun
multiget
(
urls
:
List
<
HttpUrl
>)
{
/* <!ELEMENT calendar-multiget ((DAV:allprop |
DAV:propname |
...
...
src/main/java/at/bitfire/dav4android/DavCollection.kt
View file @
1169e150
...
...
@@ -8,6 +8,8 @@
package
at.bitfire.dav4android
import
at.bitfire.dav4android.exception.DavException
import
at.bitfire.dav4android.exception.HttpException
import
at.bitfire.dav4android.property.SyncToken
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
...
...
@@ -16,7 +18,7 @@ import okhttp3.RequestBody
import
java.io.StringWriter
import
java.util.logging.Logger
open
class
DavCollection
(
open
class
DavCollection
@JvmOverloads
constructor
(
httpClient
:
OkHttpClient
,
location
:
HttpUrl
,
log
:
Logger
=
Constants
.
log
...
...
@@ -30,6 +32,10 @@ open class DavCollection(
* @param infiniteDepth sync-level to be sent with the request: false = "1", true = "infinite"
* @param limit maximum number of results (may cause truncation)
* @param properties WebDAV properties to be requested
* @throws java.io.IOException on I/O error
* @throws HttpException on HTTP error
* @throws DavException on DAV error
*/
fun
reportChanges
(
syncToken
:
String
?,
infiniteDepth
:
Boolean
,
limit
:
Int
?,
vararg
properties
:
Property
.
Name
)
{
/* <!ELEMENT sync-collection (sync-token, sync-level, limit?, prop)>
...
...
src/main/java/at/bitfire/dav4android/DavResource.kt
View file @
1169e150
...
...
@@ -429,11 +429,11 @@ open class DavResource @JvmOverloads constructor(
"prop"
->
prop
=
parseMultiStatus_Prop
()
"status"
->
try
{
status
=
StatusLine
.
parse
(
parser
.
nextText
())
status
=
try
{
StatusLine
.
parse
(
parser
.
nextText
())
}
catch
(
e
:
ProtocolException
)
{
log
.
warning
(
"Invalid status line, treating as 500 Server Error"
)
status
=
StatusLine
(
Protocol
.
HTTP_1_1
,
500
,
"Invalid status line"
)
StatusLine
(
Protocol
.
HTTP_1_1
,
500
,
"Invalid status line"
)
}
}
eventType
=
parser
.
next
()
...
...
@@ -485,11 +485,11 @@ open class DavResource @JvmOverloads constructor(
href
=
location
.
resolve
(
sHref
)
}
"status"
->
try
{
status
=
StatusLine
.
parse
(
parser
.
nextText
())
status
=
try
{
StatusLine
.
parse
(
parser
.
nextText
())
}
catch
(
e
:
ProtocolException
)
{
log
.
warning
(
"Invalid status line, treating as 500 Server Error"
)
status
=
StatusLine
(
Protocol
.
HTTP_1_1
,
500
,
"Invalid status line"
)
StatusLine
(
Protocol
.
HTTP_1_1
,
500
,
"Invalid status line"
)
}
"propstat"
->
parseMultiStatus_PropStat
()
?.
let
{
properties
.
merge
(
it
,
false
)
}
...
...
src/main/java/at/bitfire/dav4android/HttpUtils.kt
View file @
1169e150
...
...
@@ -17,13 +17,11 @@ object HttpUtils {
private
val
authSchemeWithParam
=
Pattern
.
compile
(
"^([^ \"]+) +(.*)$"
)
@JvmStatic
fun
listHeader
(
response
:
Response
,
name
:
String
):
Array
<
String
>
{
val
value
=
response
.
headers
(
name
).
joinToString
(
","
)
return
value
.
split
(
','
).
filter
{
it
.
isNotEmpty
()
}.
toTypedArray
()
}
@JvmStatic
fun
parseWwwAuthenticate
(
wwwAuths
:
List
<
String
>):
List
<
AuthScheme
>
{
/* WWW-Authenticate = "WWW-Authenticate" ":" 1#challenge
...
...
src/main/java/at/bitfire/dav4android/Property.kt
View file @
1169e150
...
...
@@ -11,7 +11,7 @@ package at.bitfire.dav4android
/**
* A WebDAV property.
*
* Every [Property] must define a static field
called NAME of type Property.Name
,
* Every [Property] must define a static field
(use @JvmStatic) called NAME of type [Property.Name]
,
* which will be accessed by reflection.
*/
interface
Property
{
...
...
@@ -21,11 +21,11 @@ interface Property {
val
name
:
String
)
{
override
fun
equals
(
o
:
Any
?):
Boolean
{
return
if
(
o
is
Name
)
namespace
==
o
.
namespace
&&
name
==
o
.
name
override
fun
equals
(
o
ther
:
Any
?):
Boolean
{
return
if
(
o
ther
is
Name
)
namespace
==
o
ther
.
namespace
&&
name
==
other
.
name
else
super
.
equals
(
o
)
super
.
equals
(
o
ther
)
}
override
fun
hashCode
()
=
namespace
.
hashCode
()
xor
name
.
hashCode
()
...
...
src/main/java/at/bitfire/dav4android/PropertyCollection.kt
View file @
1169e150
...
...
@@ -33,12 +33,12 @@ class PropertyCollection {
if
(!
properties
.
isInitialized
())
return
null
try
{
return
try
{
val
name
=
clazz
.
getDeclaredField
(
"NAME"
).
get
(
null
)
as
Property
.
Name
return
properties
.
value
[
name
]
as
?
T
properties
.
value
[
name
]
as
?
T
}
catch
(
e
:
NoSuchFieldException
)
{
Constants
.
log
.
severe
(
"$clazz does not have a static NAME field"
)
return
null
null
}
}
...
...
@@ -66,15 +66,14 @@ class PropertyCollection {
/**
* Merges another
#{@link PropertyCollection} into #{@link #properties}
.
* Merges another
[PropertyCollection] into [properties]
.
* Existing properties will be overwritten.
*
* @param another property collection to take the properties from
* @param removeNullValues Indicates how "another" properties with null values should be treated.
* <ul>
* <li>#{@code true}: If the "another" property value is #{@code null}, the property will be removed in #{@link #properties}.</li>
* <li>#{@code false}: If the "another" property value is #{@code null}, the property in #{@link #properties} will be set to null, too,
but only if it doesn't exist yet. This means values in #{@link #properties} will never be overwritten by #{@code null}.</li>
* </ul>
* - true: If the "another" property value is null, the property will be removed in [properties].
* - false: If the "another" property value is null, the property in [properties] will be set to null, too,
* but only if it doesn't exist yet. This means values in [properties] will never be overwritten by null.
*/
fun
merge
(
another
:
PropertyCollection
,
removeNullValues
:
Boolean
)
{
val
properties
=
another
.
getMap
()
...
...
src/main/java/at/bitfire/dav4android/PropertyFactory.kt
View file @
1169e150
...
...
@@ -20,7 +20,10 @@ interface PropertyFactory {
*/
fun
getName
():
Property
.
Name
@Throws
(
IOException
::
class
,
XmlPullParserException
::
class
)
/**
* Parses XML of a property and returns its data class.
* @throws XmlPullParserException in case of parsing errors
*/
fun
create
(
parser
:
XmlPullParser
):
Property
?
}
src/main/java/at/bitfire/dav4android/QuotedStringUtils.kt
View file @
1169e150
...
...
@@ -10,19 +10,10 @@ package at.bitfire.dav4android
object
QuotedStringUtils
{
@JvmStatic
fun
asQuotedString
(
raw
:
String
?):
String
?
{
return
if
(
raw
==
null
)
null
else
fun
asQuotedString
(
raw
:
String
)
=
"\""
+
raw
.
replace
(
"\\"
,
"\\\\"
).
replace
(
"\""
,
"\\\""
)
+
"\""
}
@JvmStatic
fun
decodeQuotedString
(
quoted
:
String
?):
String
?
{
if
(
quoted
==
null
)
return
null
fun
decodeQuotedString
(
quoted
:
String
):
String
{
/* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
qdtext = <any TEXT except <">>
quoted-pair = "\" CHAR
...
...
src/main/java/at/bitfire/dav4android/UrlUtils.kt
View file @
1169e150
...
...
@@ -14,7 +14,6 @@ import java.net.URISyntaxException
object
UrlUtils
{
@JvmStatic
fun
equals
(
url1
:
HttpUrl
,
url2
:
HttpUrl
):
Boolean
{
// if okhttp thinks the two URLs are equal, they're in any case
// (and it's a simple String comparison)
...
...
@@ -32,7 +31,6 @@ object UrlUtils {
}
}
@JvmStatic
fun
hostToDomain
(
host
:
String
?):
String
?
{
if
(
host
==
null
)
return
null
...
...
@@ -49,7 +47,6 @@ object UrlUtils {
host
}
@JvmStatic
fun
omitTrailingSlash
(
url
:
HttpUrl
):
HttpUrl
{
val
idxLast
=
url
.
pathSize
()
-
1
val
hasTrailingSlash
=
url
.
pathSegments
()[
idxLast
]
==
""
...
...
@@ -60,7 +57,6 @@ object UrlUtils {
url
}
@JvmStatic
fun
withTrailingSlash
(
url
:
HttpUrl
):
HttpUrl
{
val
idxLast
=
url
.
pathSize
()
-
1
val
hasTrailingSlash
=
url
.
pathSegments
()[
idxLast
]
==
""
...
...
src/main/java/at/bitfire/dav4android/XmlUtils.kt
View file @
1169e150
...
...
@@ -15,11 +15,11 @@ import java.io.IOException
object
XmlUtils
{
@JvmField
val
NS_WEBDAV
=
"DAV:"
@JvmField
val
NS_CALDAV
=
"urn:ietf:params:xml:ns:caldav"
@JvmField
val
NS_CARDDAV
=
"urn:ietf:params:xml:ns:carddav"
@JvmField
val
NS_APPLE_ICAL
=
"http://apple.com/ns/ical/"
@JvmField
val
NS_CALENDARSERVER
=
"http://calendarserver.org/ns/"
const
val
NS_WEBDAV
=
"DAV:"
const
val
NS_CALDAV
=
"urn:ietf:params:xml:ns:caldav"
const
val
NS_CARDDAV
=
"urn:ietf:params:xml:ns:carddav"
const
val
NS_APPLE_ICAL
=
"http://apple.com/ns/ical/"
const
val
NS_CALENDARSERVER
=
"http://calendarserver.org/ns/"
private
val
factory
:
XmlPullParserFactory
init
{
...
...
@@ -31,10 +31,7 @@ object XmlUtils {
}
}
@JvmStatic
fun
newPullParser
()
=
factory
.
newPullParser
()
!!
@JvmStatic
fun
newSerializer
()
=
factory
.
newSerializer
()
!!
...
...
src/main/java/at/bitfire/dav4android/exception/DavException.kt
View file @
1169e150
...
...
@@ -8,4 +8,7 @@
package
at.bitfire.dav4android.exception
open
class
DavException
@JvmOverloads
constructor
(
message
:
String
,
ex
:
Throwable
?
=
null
):
Exception
(
message
,
ex
)
\ No newline at end of file
open
class
DavException
@JvmOverloads
constructor
(
message
:
String
,
ex
:
Throwable
?
=
null
):
Exception
(
message
,
ex
)
\ No newline at end of file
src/main/java/at/bitfire/dav4android/exception/HttpException.kt
View file @
1169e150
...
...
@@ -15,8 +15,10 @@ import java.io.*
open
class
HttpException
:
Exception
,
Serializable
{
companion
object
{
// don't dump more than 20 kB
private
val
MAX_DUMP_SIZE
=
20
*
1024
private
const
val
MAX_DUMP_SIZE
=
20
*
1024
}
val
status
:
Int
val
request
:
String
?
...
...
src/main/java/at/bitfire/dav4android/exception/InvalidDavResponseException.kt
View file @
1169e150
...
...
@@ -8,4 +8,7 @@
package
at.bitfire.dav4android.exception
class
InvalidDavResponseException
(
message
:
String
,
ex
:
Throwable
?
=
null
):
DavException
(
message
,
ex
)
\ No newline at end of file
class
InvalidDavResponseException
@JvmOverloads
constructor
(
message
:
String
,
ex
:
Throwable
?
=
null
):
DavException
(
message
,
ex
)
\ No newline at end of file
src/main/java/at/bitfire/dav4android/exception/UnsupportedDavException.kt
View file @
1169e150
...
...
@@ -8,4 +8,4 @@
package
at.bitfire.dav4android.exception
class
UnsupportedDavException
(
message
:
String
)
:
DavException
(
message
)
\ No newline at end of file
class
UnsupportedDavException
(
message
:
String
):
DavException
(
message
)
\ No newline at end of file
src/main/java/at/bitfire/dav4android/property/GetETag.kt
View file @
1169e150
...
...
@@ -37,7 +37,7 @@ class GetETag(
// entity tag is weak (doesn't matter for us)
tag
=
it
.
substring
(
2
)
tag
=
QuotedStringUtils
.
decodeQuotedString
(
tag
)
tag
?.
let
{
tag
=
QuotedStringUtils
.
decodeQuotedString
(
it
)
}
}
eTag
=
tag
...
...
src/main/java/at/bitfire/dav4android/property/ResourceType.kt
View file @
1169e150
...
...
@@ -19,11 +19,11 @@ class ResourceType: Property {
@JvmField
val
NAME
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"resourcetype"
)
@JvmField
val
COLLECTION
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"collection"
)
// WebDAV
@JvmField
val
PRINCIPAL
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"principal"
)
// WebDAV ACL
@JvmField
val
ADDRESSBOOK
=
Property
.
Name
(
XmlUtils
.
NS_CARDDAV
,
"addressbook"
)
// CardDAV
@JvmField
val
CALENDAR
=
Property
.
Name
(
XmlUtils
.
NS_CALDAV
,
"calendar"
)
// CalDAV
@JvmField
val
SUBSCRIBED
=
Property
.
Name
(
XmlUtils
.
NS_CALENDARSERVER
,
"subscribed"
)
val
COLLECTION
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"collection"
)
// WebDAV
val
PRINCIPAL
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"principal"
)
// WebDAV ACL
val
ADDRESSBOOK
=
Property
.
Name
(
XmlUtils
.
NS_CARDDAV
,
"addressbook"
)
// CardDAV
val
CALENDAR
=
Property
.
Name
(
XmlUtils
.
NS_CALDAV
,
"calendar"
)
// CalDAV
val
SUBSCRIBED
=
Property
.
Name
(
XmlUtils
.
NS_CALENDARSERVER
,
"subscribed"
)
}
val
types
=
mutableSetOf
<
Property
.
Name
>()
...
...
src/main/java/at/bitfire/dav4android/property/SupportedReportSet.kt
View file @
1169e150
...
...
@@ -16,9 +16,9 @@ import org.xmlpull.v1.XmlPullParser
class
SupportedReportSet
:
Property
{
companion
object
{
@JvmField
val
NAME
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"supported-report-set"
)
val
NAME
=
Property
.
Name
(
XmlUtils
.
NS_WEBDAV
,
"supported-report-set"
)
@JvmField
val
SYNC_COLLECTION
=
"DAV:sync-collection"
// collection synchronization (RFC 6578)
val
SYNC_COLLECTION
=
"DAV:sync-collection"
// collection synchronization (RFC 6578)
}
val
reports
=
mutableSetOf
<
String
>()
...
...
src/test/java/at/bitfire/dav4android/BasicDigestAuthHandlerTest.
java
→
src/test/java/at/bitfire/dav4android/BasicDigestAuthHandlerTest.
kt
View file @
1169e150
This diff is collapsed.
Click to expand it.
src/test/java/at/bitfire/dav4android/HttpUtilsTest.java
deleted
100644 → 0
View file @
568f0285
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package
at.bitfire.dav4android
;
import
org.junit.Test
;
import
java.util.Arrays
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
HttpUtilsTest
{
@Test
public
void
testParseWwwAuthenticate
()
{
// two schemes: one without param (illegal!), second with two params
List
<
HttpUtils
.
AuthScheme
>
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
" UnknownWithoutParam, Unknown WithParam1=\"a\", Param2 "
}));
assertEquals
(
2
,
schemes
.
size
());
assertEquals
(
"UnknownWithoutParam"
,
schemes
.
get
(
0
).
getName
());
assertEquals
(
0
,
schemes
.
get
(
0
).
getParams
().
size
());
assertEquals
(
0
,
schemes
.
get
(
0
).
getUnnamedParams
().
size
());
assertEquals
(
"Unknown"
,
schemes
.
get
(
1
).
getName
());
assertEquals
(
1
,
schemes
.
get
(
1
).
getParams
().
size
());
assertEquals
(
"a"
,
schemes
.
get
(
1
).
getParams
().
get
(
"withparam1"
));
assertEquals
(
1
,
schemes
.
get
(
1
).
getParams
().
size
());
assertEquals
(
1
,
schemes
.
get
(
1
).
getUnnamedParams
().
size
());
assertEquals
(
"Param2"
,
schemes
.
get
(
1
).
getUnnamedParams
().
get
(
0
));
// parameters with quoted strings with commas
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"X-MyScheme param1, param2=\"a,\\\"b\\\",c\", MyOtherScheme paramA"
}));
assertEquals
(
2
,
schemes
.
size
());
assertEquals
(
"X-MyScheme"
,
schemes
.
get
(
0
).
getName
());
assertEquals
(
1
,
schemes
.
get
(
0
).
getParams
().
size
());
assertEquals
(
"a,\"b\",c"
,
schemes
.
get
(
0
).
getParams
().
get
(
"param2"
));
assertEquals
(
1
,
schemes
.
get
(
0
).
getUnnamedParams
().
size
());
assertEquals
(
"param1"
,
schemes
.
get
(
0
).
getUnnamedParams
().
get
(
0
));
assertEquals
(
"MyOtherScheme"
,
schemes
.
get
(
1
).
getName
());
assertEquals
(
0
,
schemes
.
get
(
1
).
getParams
().
size
());
assertEquals
(
1
,
schemes
.
get
(
1
).
getUnnamedParams
().
size
());
assertEquals
(
"paramA"
,
schemes
.
get
(
1
).
getUnnamedParams
().
get
(
0
));
/*** REAL WORLD EXAMPLES ***/
// Basic auth
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"Basic realm=\"test\""
}));
assertEquals
(
1
,
schemes
.
size
());
HttpUtils
.
AuthScheme
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"Basic"
,
scheme
.
getName
());
assertEquals
(
1
,
scheme
.
getParams
().
size
());
assertEquals
(
"test"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
// Basic and Digest auth in one line
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"Basic realm=\"testrealm@host.com\", Digest realm=\"testrealm@host.com\", qop=\"auth,auth-int\", nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", opaque=\"5ccc069c403ebaf9f0171e9517f40e41\""
}));
assertEquals
(
2
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"Basic"
,
scheme
.
getName
());
assertEquals
(
1
,
scheme
.
getParams
().
size
());
assertEquals
(
"testrealm@host.com"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
scheme
=
schemes
.
get
(
1
);
assertEquals
(
"Digest"
,
scheme
.
getName
());
assertEquals
(
4
,
scheme
.
getParams
().
size
());
assertEquals
(
"testrealm@host.com"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
"auth,auth-int"
,
scheme
.
getParams
().
get
(
"qop"
));
assertEquals
(
"dcd98b7102dd2f0e8b11d0f600bfb0c093"
,
scheme
.
getParams
().
get
(
"nonce"
));
assertEquals
(
"5ccc069c403ebaf9f0171e9517f40e41"
,
scheme
.
getParams
().
get
(
"opaque"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
// Negotiate (RFC 4559)
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"Negotiate"
}));
assertEquals
(
1
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"Negotiate"
,
scheme
.
getName
());
assertEquals
(
0
,
scheme
.
getParams
().
size
());
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"Negotiate a87421000492aa874209af8bc028"
}));
assertEquals
(
1
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"Negotiate"
,
scheme
.
getName
());
assertEquals
(
0
,
scheme
.
getParams
().
size
());
assertEquals
(
1
,
scheme
.
getUnnamedParams
().
size
());
assertEquals
(
"a87421000492aa874209af8bc028"
,
scheme
.
getUnnamedParams
().
get
(
0
));
// NTLM, see https://msdn.microsoft.com/en-us/library/dd944123%28v=office.12%29.aspx
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"NTLM realm=\"SIP Communications Service\", targetname=\"server.contoso.com\", version=3"
,
"Kerberos realm=\"SIP Communications Service\", targetname=\"sip/server.contoso.com\", version=3"
}));
assertEquals
(
2
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"NTLM"
,
scheme
.
getName
());
assertEquals
(
3
,
scheme
.
getParams
().
size
());
assertEquals
(
"SIP Communications Service"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
"server.contoso.com"
,
scheme
.
getParams
().
get
(
"targetname"
));
assertEquals
(
"3"
,
scheme
.
getParams
().
get
(
"version"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
scheme
=
schemes
.
get
(
1
);
assertEquals
(
"Kerberos"
,
scheme
.
getName
());
assertEquals
(
3
,
scheme
.
getParams
().
size
());
assertEquals
(
"SIP Communications Service"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
"sip/server.contoso.com"
,
scheme
.
getParams
().
get
(
"targetname"
));
assertEquals
(
"3"
,
scheme
.
getParams
().
get
(
"version"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
// https://issues.apache.org/jira/browse/HTTPCLIENT-1489
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"X-MobileMe-AuthToken realm=\"Newcastle\", Basic realm=\"Newcastle\""
}));
assertEquals
(
2
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"X-MobileMe-AuthToken"
,
scheme
.
getName
());
assertEquals
(
1
,
scheme
.
getParams
().
size
());
assertEquals
(
"Newcastle"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
scheme
=
schemes
.
get
(
1
);
assertEquals
(
"Basic"
,
scheme
.
getName
());
assertEquals
(
1
,
scheme
.
getParams
().
size
());
assertEquals
(
"Newcastle"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
0
,
scheme
.
getUnnamedParams
().
size
());
// Contacts and Calendar Server example; space in second token!
schemes
=
HttpUtils
.
parseWwwAuthenticate
(
Arrays
.
asList
(
new
String
[]{
"digest nonce=\"785592012006934833760823299624355448128925071071026584347\", realm=\"Test Realm\", algorithm=\"md5\""
}));
assertEquals
(
1
,
schemes
.
size
());
scheme
=
schemes
.
get
(
0
);
assertEquals
(
"digest"
,
scheme
.
getName
());
assertEquals
(
3
,
scheme
.
getParams
().
size
());
assertEquals
(
"785592012006934833760823299624355448128925071071026584347"
,
scheme
.
getParams
().
get
(
"nonce"
));
assertEquals
(
"Test Realm"
,
scheme
.
getParams
().
get
(
"realm"
));
assertEquals
(
"md5"
,
scheme
.
getParams
().
get
(
"algorithm"
));
}
}
src/test/java/at/bitfire/dav4android/HttpUtilsTest.kt
0 → 100644
View file @
1169e150
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package
at.bitfire.dav4android