This repository has been archived by the owner on Aug 12, 2019. It is now read-only.
/
OAuthSignatureMethodSpec.scala
77 lines (60 loc) · 2.59 KB
/
OAuthSignatureMethodSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright 2010-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package oauth
import java.util.Date
import org.specs.Specification
import common.{Full,Empty}
import http.GetRequest
import OAuthUtil.Parameter
object OAuthSignatureMethodSpec extends Specification {
val oauthAccessor = OAuthAccessor(FakeConsumer("dpf43f3p2l4k3l03","kd94hf93k423kf44"), Full("pfkkdhi9sl3r4s00"), Empty)
val hmacSha1 = HMAC_SHA1(oauthAccessor)
"OAuthSignatureMethod" should {
"normalizeUrl correctly" in {
hmacSha1.normalizeUrl("htTp://a.com:80/b?foo=bar") must_== ("http://a.com/b")
hmacSha1.normalizeUrl("htTp://a.com:123/b?foo=bar") must_== ("http://a.com:123/b")
hmacSha1.normalizeUrl("htTps://a.com:443/b?foo=bar") must_== ("https://a.com/b")
hmacSha1.normalizeUrl("htTp://a.com/b/f/") must_== ("http://a.com/b/f/")
hmacSha1.normalizeUrl("htTp://a.com?foo=bar") must_== ("http://a.com/")
}
}
"HMAC_SHA1" should {
"Create expected signature from example at http://hueniverse.com/2008/10/beginners-guide-to-oauth-part-iv-signing-requests/" in {
val oauthMessage = new OAuthMessage(GetRequest, "http://photos.example.net/photos", List(
Parameter("file","vacation.jpg"),
Parameter("size","original"),
Parameter("oauth_consumer_key","dpf43f3p2l4k3l03"),
Parameter("oauth_nonce","kllo9940pd9333jh"),
Parameter("oauth_signature_method","HMAC-SHA1"),
Parameter("oauth_timestamp","1191242096"),
Parameter("oauth_token","nnch734d00sl2jdk"),
Parameter("oauth_version","1.0")
))
val baseString = hmacSha1.getBaseString(oauthMessage)
hmacSha1.getSignature(baseString) must_== Full("tR3+Ty81lMeYAr/Fid0kMTYa/WM=")
}
}
case class FakeConsumer(consumerKey:String, consumerSecret:String) extends OAuthConsumer {
def reset{}
def enabled: Int = 0
def user: OAuthUser = new OAuthUser(){}
def title: String = ""
def applicationUri: String = ""
def callbackUri: String = ""
def xdatetime: Date = new Date(0)
}
}