Ejemplo n.º 1
0
func TestSerializeJsonBody(t *testing.T) {
	roles := types.NewLTIRoles("")
	roles.AddSystemRoles(types.SysAdmin)
	roles.AddInstitutionRoles(types.InstAdmin)

	ctxType, _ := types.NewLTIContextType(types.CtxTypeGroup)
	ltiMsg, _ := types.NewLTIMessage(types.LTIBasicMessage)
	ltiVer, _ := types.NewLTIVersion(types.LTIVersion1_0)

	l := LTIStdHeaders{
		ContextType:           ctxType,
		LISPersonPrimaryEmail: testPrimaryEmail,
		LISPersonFullName:     testFullName,
		LTIMessageType:        ltiMsg,
		LTIVersion:            ltiVer,
		Roles:                 roles,
	}

	reader, err := serializeJsonBody(l)
	if err != nil {
		t.Errorf("Unexpected error: Serializing LTIStdHeaders failed with unexpected error '%s'", err)
	}

	b, err := ioutil.ReadAll(reader)
	if err != nil {
		t.Errorf("Unexpected error: Reading serialized LTIStdHeader failed with unexpected error '%s'", err)
	}

	if !bytes.Contains(b, []byte(`"context_type":"urn:lti:context-type:ims/lis/Group"`)) {
		t.Errorf("Bad serialization: Context type serialized incorrectly.")
	}
	if !bytes.Contains(b, []byte(`"lis_person_name_full":"Mo Samman"`)) {
		t.Errorf("Bad serialization: Person name full serialized incorrectly.")
	}
	if !bytes.Contains(b, []byte(`"lis_person_contact_email_primary":"*****@*****.**"`)) {
		t.Errorf("Bad serialization: Person contact email serialized incorrectly.")
	}
	if !bytes.Contains(b, []byte(`"lti_message_type":"basic-lti-launch-request"`)) {
		t.Errorf("Bad serialization: LTI message type serialized incorrectly.")
	}
	if !bytes.Contains(b, []byte(`"lti_version":"LTI-1p0"`)) {
		t.Errorf("Bad serialization: LTI version serialized incorrectly.")
	}
	if !bytes.Contains(b, []byte(`"roles":"urn:lti:sysrole:ims/lis/Administrator,urn:lti:instrole:ims/lis/Administrator"`)) {
		t.Errorf("Bad serialization: Roles serialized incorrectly.")
	}
}
Ejemplo n.º 2
0
func TestSerializeUrlEncodedForm(t *testing.T) {
	roles := types.NewLTIRoles("")
	roles.AddSystemRoles(types.SysAdmin)
	roles.AddInstitutionRoles(types.InstAdmin)

	ctxType, _ := types.NewLTIContextType(types.CtxTypeGroup)
	ltiMsg, _ := types.NewLTIMessage(types.LTIBasicMessage)
	ltiVer, _ := types.NewLTIVersion(types.LTIVersion1_0)

	l := LTIStdHeaders{
		ContextType:           ctxType,
		LISPersonPrimaryEmail: testPrimaryEmail,
		LISPersonFullName:     testFullName,
		LTIMessageType:        ltiMsg,
		LTIVersion:            ltiVer,
		Roles:                 roles,
	}

	vals, err := serializeUrlEncodedForm(l)

	if err != nil {
		t.Errorf("Unexpected error: Serializing LTIStdHeaders failed with unexpected error '%s'", err)
	}
	if vals.Get(ContextType) != string(types.CtxTypeGroup) {
		t.Errorf("Bad serialization: Context type serialized as '%s' instead of '%s'.", vals.Get(ContextType), types.CtxTypeGroup)
	}
	if vals.Get(LISPersonFullName) != testFullName {
		t.Errorf("Bad serialization: Person name full serialized as '%s' instead of '%s'.", vals.Get(LISPersonFullName), testFullName)
	}
	if vals.Get(LISPersonPrimaryEmail) != testPrimaryEmail {
		t.Errorf("Bad serialization: Person contact email serialized as '%s' instead of '%s'.", vals.Get(LISPersonPrimaryEmail), testPrimaryEmail)
	}
	if vals.Get(LTIMessageType) != string(types.LTIBasicMessage) {
		t.Errorf("Bad serialization: LTI message type serialized as '%s' instead of '%s'.", vals.Get(LTIMessageType), types.LTIBasicMessage)
	}
	if vals.Get(LTIVersion) != string(types.LTIVersion1_0) {
		t.Errorf("Bad serialization: LTI version serialized as '%s' instead of '%s'.", vals.Get(LTIVersion), types.LTIVersion1_0)
	}
	if vals.Get(Roles) != "urn:lti:sysrole:ims/lis/Administrator,urn:lti:instrole:ims/lis/Administrator" {
		t.Errorf("Bad serialization: Roles serialized as '%s' instead of '%s'.", vals.Get(Roles), fmt.Sprintf("%s,%s", types.SysAdmin, types.InstAdmin))
	}
}