tokenHeader := map[string]interface{}{ "alg": "FAST", } tokenClaims := map[string]interface{}{ "user_id": "correct-user", "exp": int64(3404281214), "scope": []string{"notification_preferences.read"}, } request, err = http.NewRequest("GET", "/user_preferences", bytes.NewBuffer(body)) if err != nil { panic(err) } token, err := jwt.Parse(helpers.BuildToken(tokenHeader, tokenClaims), func(token *jwt.Token) (interface{}, error) { return []byte(application.UAAPublicKey), nil }) database = mocks.NewDatabase() context = stack.NewContext() context.Set("token", token) context.Set("database", database) builder = services.NewPreferencesBuilder() builder.Add(models.Preference{ ClientID: "raptorClient", KindID: "hungry-kind", Email: false, })
context = stack.NewContext() }) Context("when the request contains a valid auth token", func() { BeforeEach(func() { tokenHeader := map[string]interface{}{ "alg": "FAST", } tokenClaims := map[string]interface{}{ "jti": "c5f6a266-5cf0-4ae2-9647-2615e7d28fa1", "client_id": "mister-client", "cid": "mister-client", "exp": 3404281214, "scope": []string{"gaben.scope"}, } rawToken = helpers.BuildToken(tokenHeader, tokenClaims) requestBody, err := json.Marshal(map[string]string{ "kind": "forgot_password", "text": "Try to remember your password next time", }) if err != nil { panic(err) } request, err = http.NewRequest("POST", "/users/user-123", bytes.NewReader(requestBody)) if err != nil { panic(err) } request.Header.Set("Authorization", "Bearer "+rawToken) })