Esempio n. 1
0
func TestParseCapabilitiesRelativeUrls(t *testing.T) {
	body :=
		`<RETS ReplyCode="0" ReplyText="V2.7.0 2315: Success">
	<RETS-RESPONSE>
	MemberName=Threewide Corporation
	User=2000343, Association Member Primary:Login:Media Restrictions:Office:RETS:RETS Advanced:RETS Customer:System-MRIS:MDS Access Common:MDS Application Login, 90, TURD1
	Broker=TWD,1
	MetadataVersion=1.12.30
	MinMetadataVersion=1.1.1
	OfficeList=TWD;1
	TimeoutSeconds=1800
	Login=/platinum/login
	Action=/platinum/get?Command=Message
	Search=/platinum/search
	Get=/platinum/get
	GetObject=/platinum/getobject
	Logout=/platinum/logout
	GetMetadata=/platinum/getmetadata
	ChangePassword=/platinum/changepassword
	</RETS-RESPONSE>
	</RETS>`
	urls, err := parseCapability("http://server.com:6103/platinum/login", []byte(body))
	testutils.Ok(t, err)

	testutils.Equals(t, urls.Response.ReplyText, "V2.7.0 2315: Success")
	testutils.Equals(t, urls.Response.ReplyCode, 0)
	testutils.Equals(t, urls.Login, "http://server.com:6103/platinum/login")
	testutils.Equals(t, urls.GetMetadata, "http://server.com:6103/platinum/getmetadata")
}
Esempio n. 2
0
func TestPrependHost(t *testing.T) {
	login := "******"
	abs := "http://server.com:6103/platinum/search"
	rel := "/platinum/search"
	testutils.Equals(t, abs, prependHost(login, abs))
	testutils.Equals(t, abs, prependHost(login, rel))
}
Esempio n. 3
0
func TestParseGetObjectQuit(t *testing.T) {
	extracted := extractBoundary(contentType)

	testutils.Equals(t, boundary, extracted)

	body := ioutil.NopCloser(bytes.NewReader([]byte(multipartBody)))

	quit := make(chan struct{})
	defer close(quit)
	results := parseGetObjectsResult(quit, extracted, body)

	r1 := <-results
	testutils.Ok(t, r1.Err)
	testutils.Assert(t, r1 != GetObjectResult{}, "should not be the zerod object")
	o1 := r1.Object
	testutils.Equals(t, "image/jpeg", o1.ContentType)
	testutils.Equals(t, "123456", o1.ContentId)
	testutils.Equals(t, 1, o1.ObjectId)

	quit <- struct{}{}

	// the closed channel will emit a zero'd value of the proper type
	r2 := <-results
	testutils.Equals(t, r2, GetObjectResult{})
}
Esempio n. 4
0
func TestGetObject(t *testing.T) {
	header := http.Header{}
	textproto.MIMEHeader(header).Add("Content-Type", "image/jpeg")
	textproto.MIMEHeader(header).Add("Content-ID", "123456")
	textproto.MIMEHeader(header).Add("Object-ID", "1")
	textproto.MIMEHeader(header).Add("Preferred", "1")
	textproto.MIMEHeader(header).Add("UID", "1a234234234")
	textproto.MIMEHeader(header).Add("Content-Description", "Outhouse")
	textproto.MIMEHeader(header).Add("Content-Sub-Description", "The urinal")
	textproto.MIMEHeader(header).Add("Location", "http://www.simpleboundary.com/image-5.jpg")

	var body string = `<binary data 1>`
	reader := ioutil.NopCloser(bytes.NewReader([]byte(body)))

	quit := make(chan struct{})
	defer close(quit)
	results := parseGetObjectResult(quit, header, reader)
	result := <-results

	o := result.Object
	testutils.Ok(t, result.Err)
	testutils.Equals(t, true, o.Preferred)
	testutils.Equals(t, "image/jpeg", o.ContentType)
	testutils.Equals(t, "123456", o.ContentId)
	testutils.Equals(t, 1, o.ObjectId)
	testutils.Equals(t, "1a234234234", o.Uid)
	testutils.Equals(t, "Outhouse", o.Description)
	testutils.Equals(t, "The urinal", o.SubDescription)
	testutils.Equals(t, "<binary data 1>", string(o.Blob))
	testutils.Equals(t, "http://www.simpleboundary.com/image-5.jpg", o.Location)
	testutils.Equals(t, false, o.RetsError)
}
func verifyParseResources(t *testing.T, ms Metadata) {
	testutils.Equals(t, "1.12.30", ms.Resources.Version)
	testutils.Equals(t, len(ms.Resources.Rows), 2)

	indexer := ms.Resources.Indexer()

	testutils.Equals(t, "ActiveAgent", indexer("ResourceID", 0))
	testutils.Equals(t, "Tue, 3 Sep 2013 00:00:00 GMT", indexer("ValidationExternalDate", 1))
}
Esempio n. 6
0
func TestCompactRowParsing(t *testing.T) {
	var col string = `	A	B	C	D	E	F	`
	var row string = `	1	2	3	4		6	`
	var delim string = `	`
	headers := ParseCompactRow(col, delim)
	values := ParseCompactRow(row, delim)

	testutils.Equals(t, 6, int(len(headers)))
	testutils.Equals(t, 6, int(len(values)))
}
func verifyParseTable(t *testing.T, ms Metadata) {
	mdata := ms.Tables["ActiveAgent:ActiveAgent"]

	testutils.Equals(t, "1.12.29", mdata.Version)
	testutils.Equals(t, len(mdata.Rows), 4)

	indexer := mdata.Indexer()

	testutils.Equals(t, "AgentListingServiceName", indexer("SystemName", 0))
	testutils.Equals(t, "0", indexer("Unique", 3))
}
func verifyParseLookup(t *testing.T, ms Metadata) {
	mdata := ms.Lookups["TaxHistoricalDesignation"]

	testutils.Equals(t, "1.12.29", mdata.Version)
	testutils.Equals(t, len(mdata.Rows), 4)

	indexer := mdata.Indexer()

	testutils.Equals(t, "COUNTIES_OR_REGIONS", indexer("LookupName", 0))
	testutils.Equals(t, "Tue, 3 Sep 2013 00:00:00 GMT", indexer("Date", 3))
}
func verifyParseLookupType(t *testing.T, ms Metadata) {
	mdata := ms.LookupTypes["TaxHistoricalDesignation:COUNTIES_OR_REGIONS"]

	testutils.Equals(t, "1.12.29", mdata.Version)
	testutils.Equals(t, len(mdata.Rows), 4)

	indexer := mdata.Indexer()

	testutils.Equals(t, "BROOMFIELD-CO", indexer("LongValue", 2))
	testutils.Equals(t, "CLARK", indexer("ShortValue", 3))
}
func verifyParseClass(t *testing.T, ms Metadata) {
	mdata := ms.Classes["Property"]

	testutils.Equals(t, mdata.Version, "1.12.29")
	testutils.Equals(t, len(mdata.Rows), 6)

	indexer := mdata.Indexer()

	testutils.Equals(t, "RESO_PROP_2012_05", indexer("ClassName", 5))
	testutils.Equals(t, "Tue, 3 Sep 2013 00:00:00 GMT", indexer("TableDate", 0))
	testutils.Equals(t, "MRIS Multi-Family", indexer("VisibleName", 2))
}
func verifyCompactData(t *testing.T, pl *PayloadList, id string) {
	payload := <-pl.Payloads
	testutils.Equals(t, 6, len(payload.Columns))

	testutils.Equals(t, id, payload.Id)
	testutils.Equals(t, "A,B,C,D,E,F", strings.Join(payload.Columns, ","))

	counter := 0
	for _, row := range payload.Rows {
		testutils.Assert(t, strings.Join(row, ",") == "1,2,3,4,5,6", fmt.Sprintf("bad row %d: %s", counter, row))

		testutils.Ok(t, pl.Error)
		counter = counter + 1
	}
	testutils.Equals(t, 8, counter)
}
Esempio n. 12
0
func TestCreateHa2(t *testing.T) {
	method, uri := "GET", "/platinum/login"

	expected := "1b11c4ebed4a67753078be8020ea9d19"
	actual := createNoQopDigest().createHa2(method, uri, md5.New())

	testutils.Equals(t, expected, actual)
}
Esempio n. 13
0
func TestCreateHa1Md5(t *testing.T) {
	username := "******"
	password := "******"
	cnonce := "6ac2c2eee85f5c33"

	expected := "5c0da895491be93b455ebb56f7ae0a9f"
	actual := createNoQopDigest().createHa1(username, password, cnonce, md5.New())

	testutils.Equals(t, expected, actual)
}
Esempio n. 14
0
func TestCreateResponseQopAuth(t *testing.T) {
	nc := "00000001"
	cnonce := "6ac2c2eee85f5c33"
	ha1 := "5c0da895491be93b455ebb56f7ae0a9f"
	ha2 := "1b11c4ebed4a67753078be8020ea9d19"

	expected := "28552064c4cde9a3af7610e7ae286d50"
	actual := createAuthDigest().createResponse(ha1, ha2, nc, cnonce, md5.New())

	testutils.Equals(t, expected, actual)
}
Esempio n. 15
0
func TestCreateResponseNoQop(t *testing.T) {
	nc := "00000001"
	cnonce := "6ac2c2eee85f5c33"
	ha1 := "5c0da895491be93b455ebb56f7ae0a9f"
	ha2 := "1b11c4ebed4a67753078be8020ea9d19"

	expected := "5f8d366fb430e9b395a84dba52247a35"
	actual := createNoQopDigest().createResponse(ha1, ha2, nc, cnonce, md5.New())

	testutils.Equals(t, expected, actual)
}
Esempio n. 16
0
func TestDigest(t *testing.T) {
	username, password := "******", "passwd"

	wwwAuthenticate := `Digest realm="*****@*****.**", nonce="31333739363738363932323632201e00230a639db77779b354d601ee5d2e", opaque="6e6f742075736564"`

	expected := `Digest username="******", realm="*****@*****.**", nonce="31333739363738363932323632201e00230a639db77779b354d601ee5d2e", uri="/platinum/login", response="5f8d366fb430e9b395a84dba52247a35", algorithm="MD5", opaque="6e6f742075736564"`

	t.Logf("CHALLENGE: %s", wwwAuthenticate)

	method, uri := "GET", "/platinum/login"

	actual := createNoQopDigest().CreateDigestResponse(username, password, method, uri)

	testutils.Equals(t, expected, actual)
}
Esempio n. 17
0
func TestProcessResponseBodyNoConnectTime(t *testing.T) {
	actual, err := processResponseBody(`<RETS ReplyCode="0" ReplyText="Logging out">
						 				<RETS-RESPONSE>
						 				Billing=Im Billing You
						 				SignOffMessage=Goodbye
						 				</RETS-RESPONSE>
		                 				</RETS>`)

	if err != nil {
		t.Fail()
	}

	expected := &LogoutResponse{ReplyCode: 0, ReplyText: "Logging out", Billing: "Im Billing You", SignOffMessage: "Goodbye"}

	testutils.Equals(t, expected, actual)
}
Esempio n. 18
0
func TestProcessResponseBodyFull(t *testing.T) {
	actual, err := processResponseBody(`<RETS ReplyCode="0" ReplyText="Logging out">
						 				<RETS-RESPONSE>
						 				ConnectTime=12345
						 				Billing=Im Billing You
						 				SignOffMessage=Goodbye
						 				</RETS-RESPONSE>
		                 				</RETS>`)

	if err != nil {
		t.Fail()
	}

	expected := &LogoutResponse{0, "Logging out", 12345, "Im Billing You", "Goodbye"}

	testutils.Equals(t, expected, actual)
}
Esempio n. 19
0
func TestCreateHa1Md5Sess(t *testing.T) {
	username := "******"
	password := "******"
	cnonce := "6ac2c2eee85f5c33"

	wwwAuthenticate := `Digest realm="*****@*****.**", nonce="31333739363738363932323632201e00230a639db77779b354d601ee5d2e", opaque="6e6f742075736564, algorithm="MD5-sess"`

	digest, err := NewDigest(wwwAuthenticate)
	if err != nil {
		t.Fail()
	}

	expected := "f1843845124dcba66fef064f5aa7a782"
	actual := digest.createHa1(username, password, cnonce, md5.New())

	testutils.Equals(t, expected, actual)
}
Esempio n. 20
0
func TestDigestQopAuth(t *testing.T) {
	username, password := "******", "passwd"

	wwwAuthenticate := `Digest realm="*****@*****.**",nonce="cbbaac704d6762fa2e4c37bb84ffddb8",opaque="77974390-589f-4ec6-b67c-4a9fc096c03f",qop="auth"`
	expected := `Digest username="******", realm="*****@*****.**", nonce="cbbaac704d6762fa2e4c37bb84ffddb8", uri="/rets/login", response="3b2ce903001cf00a264c69674d691526", qop=auth, nc=00000001, cnonce="6ac2c2eee85f5c33", algorithm="MD5", opaque="77974390-589f-4ec6-b67c-4a9fc096c03f"`

	t.Logf("CHALLENGE: %s", wwwAuthenticate)

	method, uri := "GET", "/rets/login"
	cnonce := "6ac2c2eee85f5c33"

	dig, err := NewDigest(wwwAuthenticate)
	if err != nil {
		t.Fail()
	}
	actual := dig.computeAuthorization(username, password, method, uri, cnonce)

	testutils.Equals(t, expected, actual)
}
Esempio n. 21
0
func TestParseChallenge(t *testing.T) {
	wwwAuthenticate := `Digest realm="*****@*****.**", nonce="31333739363738363932323632201e00230a639db77779b354d601ee5d2e", opaque="6e6f742075736564"`

	digest, err := NewDigest(wwwAuthenticate)
	if err != nil {
		t.Fail()
	}

	expected := &Digest{
		Realm:      "*****@*****.**",
		Nonce:      "31333739363738363932323632201e00230a639db77779b354d601ee5d2e",
		Algorithm:  "MD5",
		Opaque:     "6e6f742075736564",
		Qop:        "",
		NonceCount: 1,
	}

	testutils.Equals(t, expected, digest)
}
Esempio n. 22
0
func TestExtractBoundary(t *testing.T) {
	extracted := extractBoundary(contentType)

	testutils.Equals(t, boundary, extracted)
}
Esempio n. 23
0
func TestGetObjects(t *testing.T) {
	extracted := extractBoundary(contentType)

	testutils.Equals(t, boundary, extracted)

	body := ioutil.NopCloser(bytes.NewReader([]byte(multipartBody)))

	quit := make(chan struct{})
	defer close(quit)
	results := parseGetObjectsResult(quit, extracted, body)

	r1 := <-results
	testutils.Ok(t, r1.Err)
	o1 := r1.Object
	testutils.Equals(t, true, o1.Preferred)
	testutils.Equals(t, "image/jpeg", o1.ContentType)
	testutils.Equals(t, "123456", o1.ContentId)
	testutils.Equals(t, 1, o1.ObjectId)
	testutils.Equals(t, "<binary data 1>", string(o1.Blob))
	testutils.Equals(t, "123456", o1.ObjectData["ListingKey"])
	testutils.Equals(t, "2013-05-01T12:34:34.8-0500", o1.ObjectData["ListDate"])

	r2 := <-results
	testutils.Ok(t, r2.Err)
	o2 := r2.Object
	testutils.Equals(t, 2, o2.ObjectId)
	testutils.Equals(t, "1a234234234", o2.Uid)

	r3 := <-results
	testutils.Ok(t, r3.Err)
	o3 := r3.Object
	testutils.Equals(t, 3, o3.ObjectId)
	testutils.Equals(t, "Outhouse", o3.Description)
	testutils.Equals(t, "The urinal", o3.SubDescription)

	r4 := <-results
	testutils.Ok(t, r4.Err)
	o4 := r4.Object
	testutils.Equals(t, true, o4.RetsError)

	testutils.Equals(t, "text/xml", o4.ContentType)
	testutils.Equals(t, "There is no object with that Object-ID", o4.RetsErrorMessage.ReplyText)
	testutils.Equals(t, 20403, o4.RetsErrorMessage.ReplyCode)

	r5 := <-results
	testutils.Ok(t, r5.Err)
	o5 := r5.Object
	testutils.Equals(t, "http://www.simpleboundary.com/image-5.jpg", o5.Location)
	testutils.Equals(t, "image/jpeg", o5.ContentType)
	testutils.Equals(t, "123456", o5.ContentId)
	testutils.Equals(t, 5, o5.ObjectId)
	testutils.Equals(t, "<binary data 5>", string(o5.Blob))

}