1
+ {-# LANGUAGE OverloadedStrings #-}
2
+ module Kubernetes.Client.Auth.BasicSpec where
3
+
4
+ import Test.Hspec
5
+ import Data.Typeable
6
+ import Data.Maybe ( isJust
7
+ , isNothing
8
+ , fromJust
9
+ )
10
+ import Kubernetes.Client.Auth.Basic
11
+ import Kubernetes.Client.KubeConfig
12
+ import Kubernetes.OpenAPI
13
+ import Network.TLS ( defaultParamsClient )
14
+
15
+ emptyAuthInfo :: AuthInfo
16
+ emptyAuthInfo = AuthInfo Nothing
17
+ Nothing
18
+ Nothing
19
+ Nothing
20
+ Nothing
21
+ Nothing
22
+ Nothing
23
+ Nothing
24
+ Nothing
25
+ Nothing
26
+ Nothing
27
+ Nothing
28
+
29
+ spec :: Spec
30
+ spec = do
31
+ let testTLSParams = defaultParamsClient " " " "
32
+ testUsername = Just " testuser"
33
+ testPassword = Just " testpassword"
34
+ basicAuthInfo = emptyAuthInfo { username = testUsername, password = testPassword}
35
+ describe " Basic Authentication" $ do
36
+ it " should return Nothing if the username an d/or password is not provided" $ do
37
+ testConfig <- newConfig
38
+ isNothing (basicAuth emptyAuthInfo (testTLSParams, testConfig))
39
+ `shouldBe` True
40
+ isNothing (basicAuth emptyAuthInfo { username = testUsername} (testTLSParams, testConfig))
41
+ `shouldBe` True
42
+ isNothing (basicAuth emptyAuthInfo { password = testUsername} (testTLSParams, testConfig))
43
+ `shouldBe` True
44
+
45
+ context " when username and password are provided" $ do
46
+ it " should return a configuration provider io" $ do
47
+ testConfig <- newConfig
48
+ isJust (basicAuth basicAuthInfo (testTLSParams, testConfig)) `shouldBe` True
49
+
50
+ it " should configure basic auth" $ do
51
+ testConfig <- newConfig
52
+ (_, (KubernetesClientConfig { configAuthMethods = AnyAuthMethod (a) : as })) <-
53
+ fromJust $ basicAuth basicAuthInfo (testTLSParams, testConfig)
54
+ null as `shouldBe` True
55
+ isJust (cast a :: Maybe BasicAuth ) `shouldBe` True
0 commit comments