Пример #1
0
		Context("when the token is valid", func() {
			BeforeEach(func() {
				claims := map[string]interface{}{
					"exp":   3404281214,
					"scope": []string{"route.advertise"},
				}
				token.Claims = claims

				signedKey, err = token.SignedString([]byte(UserPrivateKey))
				Expect(err).NotTo(HaveOccurred())

				signedKey = "bearer " + signedKey
			})

			It("does not return an error", func() {
				err := accessToken.DecodeToken(signedKey, "route.advertise")
				Expect(err).NotTo(HaveOccurred())
			})
		})

		Context("when a token is not valid", func() {
			It("returns an error if the user token is not signed", func() {
				err = accessToken.DecodeToken("bearer not-a-signed-key", "not a permission")
				Expect(err).To(HaveOccurred())
			})

			It("returns an invalid token format when there is no token type", func() {
				err = accessToken.DecodeToken("has-no-token-type", "not a permission")

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(Equal("Invalid token format"))