package Ġorg . http 4 k . filter Ċ Ċ import Ġcom . nat pr y ce . ham k rest . assertion . assertThat Ċ import Ġorg . http 4 k . core . Credentials Ċ import Ġorg . http 4 k . core . Method . GET Ċ import Ġorg . http 4 k . core . Request Ċ import Ġorg . http 4 k . core . Response Ċ import Ġorg . http 4 k . core . Status . Companion . OK Ċ import Ġorg . http 4 k . core . Status . Companion . UN AUTHORIZ ED Ċ import Ġorg . http 4 k . core . then Ċ import Ġorg . http 4 k . ham k rest . has Header Ċ import Ġorg . http 4 k . ham k rest . has Status Ċ import Ġorg . http 4 k . security . digest . Digest Mode Ċ import Ġorg . http 4 k . security . digest . Q op . Auth Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ class ĠDigest Auth Test Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġpassword Lookup : Ġ( String ) Ġ-> ĠString ? Ġ= Ġ{ Ġif Ġ( it Ġ== Ġ" admin ") Ġ" password " Ġelse Ġnull Ġ} ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval Ġrealm Ġ= Ġ" http 4 k " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` invalid Ġcredentials `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Ġ= ĠServer Filters . Digest Auth ( realm , Ġpassword Lookup ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. then Ġ{ ĠResponse ( OK ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠClient Filters . Digest Auth ( Credentials (" admin ", Ġ" h unter 2 ")). then ( handler )( Request ( GET , Ġ"/ ")) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġhas Status ( UN AUTHORIZ ED )) ĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġ! has Header (" WW W - Authenticate ", Ġ"")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` valid Ġcredentials Ġwith ĠAuth ĠQ op `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠServer Filters . Digest Auth ( realm , Ġpassword Lookup , ĠlistOf ( Auth )). then Ġ{ ĠResponse ( OK ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠClient Filters . Digest Auth ( Credentials (" admin ", Ġ" password ")). then ( handler )( Request ( GET , Ġ"/ ")) ĊĊĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġhas Status ( OK )) ĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġ! has Header (" WW W - Authenticate ", Ġ"")) ĊĠĠĠ Ġ} Ċ Ċ // ĠĠĠ Ġ@ Test ĠTODO Ġnot Ġfully Ġimplemented Ċ // ĠĠĠ Ġfun Ġ` valid Ġcredentials Ġwith ĠAuth - Int ĠQ op `() Ġ{ Ċ // ĠĠĠĠĠĠĠ Ġval Ġhandler Ġ= ĠServer Filters . Digest Auth ( realm , Ġpassword Lookup , Ġq op Ġ= ĠlistOf ( Q op . Auth Int )). then Ġ{ ĠResponse ( Status . OK ) Ġ} Ċ // ĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠClient Filters . Digest Auth ( Credentials (" admin ", Ġ" password ")). then ( handler )( Request ( Method . GET , Ġ"/ ")) Ċ // Ċ // ĠĠĠĠĠĠĠ ĠassertThat ( response . status , ĠequalTo ( Status . OK )) Ċ // ĠĠĠĠĠĠĠ ĠassertThat ( response . header (" WW W - Authenticate "), Ġis Null Or Blank ) Ċ // ĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` valid Ġcredentials Ġwith Ġno Ġq op `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Ġ= ĠServer Filters . Digest Auth ( realm , Ġpassword Lookup , Ġempty List ()). then Ġ{ ĠResponse ( OK ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠClient Filters . Digest Auth ( Credentials (" admin ", Ġ" password ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. then ( handler )( Request ( GET , Ġ"/ ")) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġhas Status ( OK )) ĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġ! has Header (" WW W - Authenticate ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` valid Ġcredentials Ġin Ġproxy Ġmode `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġhandler Ġ= ĠServer Filters . Digest Auth ( realm , Ġpassword Lookup , Ġdigest Mode Ġ= ĠDigest Mode . Proxy ). then Ġ{ ĠResponse ( OK ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠClient Filters . Digest Auth ( Credentials (" admin ", Ġ" password "), Ġdigest Mode Ġ= ĠDigest Mode . Proxy ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. then ( handler )( Request ( GET , Ġ"/ ")) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( response , Ġhas Status ( OK )) ĊĠĠĠ Ġ} Ċ } Ċ