Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make an expired cookie #177

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gu.pandomainauth

import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.gu.pandomainauth.model.AuthenticatedUser
import com.gu.pandomainauth.service.CookieUtils
import com.gu.pandomainauth.service.CryptoConf.SigningAndVerification
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{EitherValues, OptionValues}

import java.time.Instant
import java.time.temporal.ChronoUnit.HOURS

class PanDomainAuthSettingsRefresherTest extends AnyFreeSpec with Matchers with EitherValues with OptionValues {

"Give an expired cookie" in {
val myRealCookie = ""// "Paste in your real cookie value here - from the 'gutoolsAuth-assym' cookie"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get this from a browser session on a real gutools site.


val s3Client =
AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_1)
.withCredentials(new ProfileCredentialsProvider("workflow")).build()

val signingAndVerification: SigningAndVerification =
PanDomainAuthSettingsRefresher("gutools.co.uk", "testing",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joe, make sure you match gutools.co.uk to the domain you got your cookie from, eg it may need to be code.dev-gutools.co.uk

S3BucketLoader.forAwsSdkV1(s3Client, "pan-domain-auth-settings")
).settings.signingAndVerification
val user: AuthenticatedUser = CookieUtils.parseCookieData(myRealCookie, signingAndVerification).value
val expiredUser = user.copy(expires = Instant.now.minus(48, HOURS).toEpochMilli)
val expiredCookieText = CookieUtils.generateCookieData(expiredUser, signingAndVerification)
println(expiredCookieText)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expired cookie output here.

}
}
Loading