mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-03 10:37:29 +01:00
Add flag to force using hex password authentication.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
cd54632339
commit
7830ed3dbf
@ -41,13 +41,17 @@ class SubsonicAPIClient(baseUrl: String,
|
||||
minimalProtocolVersion: SubsonicAPIVersions,
|
||||
clientID: String,
|
||||
allowSelfSignedCertificate: Boolean = false,
|
||||
enableLdapUserSupport: Boolean = false,
|
||||
debug: Boolean = false) {
|
||||
private val versionInterceptor = VersionInterceptor(minimalProtocolVersion) {
|
||||
protocolVersion = it
|
||||
}
|
||||
|
||||
private val proxyPasswordInterceptor = ProxyPasswordInterceptor(minimalProtocolVersion,
|
||||
PasswordHexInterceptor(password), PasswordMD5Interceptor(password))
|
||||
private val proxyPasswordInterceptor = ProxyPasswordInterceptor(
|
||||
minimalProtocolVersion,
|
||||
PasswordHexInterceptor(password),
|
||||
PasswordMD5Interceptor(password),
|
||||
enableLdapUserSupport)
|
||||
|
||||
/**
|
||||
* Get currently used protocol version.
|
||||
|
@ -7,15 +7,21 @@ import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
||||
|
||||
/**
|
||||
* Proxy [Interceptor] that uses one of [hexInterceptor] or [mD5Interceptor] depends on [apiVersion].
|
||||
*
|
||||
* To force [hexInterceptor] set [forceHexPassword] to `true`. Usually it should be done only for
|
||||
* ldap users.
|
||||
*/
|
||||
internal class ProxyPasswordInterceptor(
|
||||
initialAPIVersions: SubsonicAPIVersions,
|
||||
private val hexInterceptor: PasswordHexInterceptor,
|
||||
private val mD5Interceptor: PasswordMD5Interceptor) : Interceptor {
|
||||
private val mD5Interceptor: PasswordMD5Interceptor,
|
||||
private val forceHexPassword: Boolean = false
|
||||
) : Interceptor {
|
||||
var apiVersion: SubsonicAPIVersions = initialAPIVersions
|
||||
|
||||
override fun intercept(chain: Chain): Response =
|
||||
if (apiVersion < SubsonicAPIVersions.V1_13_0) {
|
||||
if (apiVersion < SubsonicAPIVersions.V1_13_0 ||
|
||||
forceHexPassword) {
|
||||
hexInterceptor.intercept(chain)
|
||||
} else {
|
||||
mD5Interceptor.intercept(chain)
|
||||
|
@ -6,6 +6,7 @@ import okhttp3.Interceptor.Chain
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_12_0
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_13_0
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_16_0
|
||||
|
||||
/**
|
||||
* Unit test for [ProxyPasswordInterceptor].
|
||||
@ -16,7 +17,7 @@ class ProxyPasswordInterceptorTest {
|
||||
private val mockChain = mock<Chain>()
|
||||
|
||||
private val proxyInterceptor = ProxyPasswordInterceptor(V1_12_0,
|
||||
mockPasswordHexInterceptor, mockPasswordMd5Interceptor)
|
||||
mockPasswordHexInterceptor, mockPasswordMd5Interceptor, false)
|
||||
|
||||
@Test
|
||||
fun `Should use hex password on versions less then 1 13 0`() {
|
||||
@ -33,4 +34,14 @@ class ProxyPasswordInterceptorTest {
|
||||
|
||||
verify(mockPasswordMd5Interceptor).intercept(mockChain)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should use hex password if forceHex is true`() {
|
||||
val interceptor = ProxyPasswordInterceptor(V1_16_0, mockPasswordHexInterceptor,
|
||||
mockPasswordMd5Interceptor, true)
|
||||
|
||||
interceptor.intercept(mockChain)
|
||||
|
||||
verify(mockPasswordHexInterceptor).intercept(mockChain)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user