예제 #1
0
파일: Handlers.go 프로젝트: e-gov/fox
// Mint a token for a given username and send it to the specified writer
func sendToken(w http.ResponseWriter, u string) {
	t := authn.GetToken(u)

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)

	if err := json.NewEncoder(w).Encode(authn.Token{Token: t}); err != nil {
		panic(err)
	}

}
예제 #2
0
파일: TokenMint.go 프로젝트: e-gov/fox
// Generate a token based on the key file and username
func main() {
	var keyfile string
	var username string

	flag.StringVar(&keyfile, "key", "key.base64", "A file containing the mint key")
	flag.StringVar(&username, "user", "", "Username to mint the token for")

	flag.Parse()

	authn.LoadMintKeyByName(keyfile)
	fmt.Print(authn.GetToken(username))

}
예제 #3
0
파일: authn_test.go 프로젝트: e-gov/fox
		provider  = "pwd"
	)

	s := "TEST"
	util.SetupSvcLogging(&s)

	BeforeEach(func() {
		util.LoadConfigByPathWOExtension("test_config")
		authn.InitMint()
		authn.InitValidator()
	})

	Describe("Token roundtrip", func() {
		Context("Freshly minted token", func() {
			It("Fresh token should be valid", func() {
				user, err := authn.Validate(authn.GetToken(user))
				Expect(err).To(BeNil())
				Expect(user).To(Equal(user))
			})
		})
		Context("Authenticating the user", func() {
			It("should return true, given valid username, challenge and provider", func() {
				booln := authn.Authenticate(user, challenge, provider)
				Expect(booln).To(BeTrue())
			})
		})
	})

	Describe("Reissuing a token", func() {
		Context("Username is preserved", func() {
			It("should return the username that was given to the old token", func() {
예제 #4
0
파일: fox_test.go 프로젝트: e-gov/fox
		util.LoadConfigByPathWOExtension("test_config")
		router = NewRouter()
		recorder = httptest.NewRecorder()

		aFox = Fox{
			Name:    "Rein",
			Parents: []string{"2", "3"},
		}

		anotherFox = Fox{
			Name:    "NewName",
			Parents: []string{"4", "5"},
		}
		authn.InitValidator()
		authn.InitMint()
		token = authn.GetToken("testuser")
	})

	Describe("Adding foxes", func() {
		Context("Adding, reading and updating a fox", func() {
			// Simple adding of a fox
			It("Should return 201", func() {

				// Add the fox
				foxID := addFox(aFox, router)

				// See if we can find it
				_ = getFox(foxID, router)
			})
		})
	})